Package

Source Code of Main

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import functions.*;
import functions.basic.Exp;
import functions.basic.Log;
import threads.Generator;
import threads.Integrator;
import threads.Semaphore;
import threads.SimpleGenerator;
import threads.SimpleIntegrator;
import threads.Task;
import static java.lang.Math.random;

/**
*
* @author true
*/
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        double x = Functions.integrate(new Exp(), 0, 1, 0.0000001);
        System.out.println(x);
        System.out.println("Non thread");
        nonThread();
        System.out.println("Simple");
        simpleThreads();
        System.out.println("Complicated");
        complicatedThreads();
    }

    static void nonThread() {
        Task task = new Task();
        task.count = 100;
        for (int index = 0; index < task.count; index++) {
            Function log = new Log(1 + random() * 9);
            task.func = log;
            task.leftBorder = random() * 100;
            task.rightBorder = random() * 100 + 100;
            task.delta = random();
            System.out.println("Source " + task.leftBorder + " " + task.rightBorder + " " + task.delta);
            double x = Functions.integrate(task.func, task.leftBorder, task.rightBorder, task.delta);
            System.out.println("Result " + task.leftBorder + " " + task.rightBorder + " " + task.delta + " " + x);
        }
    }

    static void simpleThreads() {
        Task task = new Task();
        task.func = new Log(1 + random() * 9);
        task.leftBorder = random() * 100;
        task.rightBorder = random() * 100 + 100;
        task.delta = random();
        task.count = 100;
        Runnable generator = new SimpleGenerator(task);
        Thread generatorThread = new Thread(generator, "Generator");
        //generatorThread.setPriority(Thread.MAX_PRIORITY);
        Runnable integrator = new SimpleIntegrator(task);
        Thread integratorThread = new Thread(integrator, "Integrator");
        //integratorThread.setPriority(Thread.MAX_PRIORITY);
        //System.err.println("" + generatorThread.getPriority() + " " + integratorThread.getPriority());
        generatorThread.start();
        integratorThread.start();
    }

    static void complicatedThreads() {
        Task task = new Task();
        task.count = 100;
        Semaphore semaphore = new Semaphore();
        Thread generatorThread = new Generator(task, semaphore, "Generator");
        //generatorThread.setPriority(Thread.MAX_PRIORITY);
        Thread integratorThread = new Integrator(task, semaphore, "Integrator");
        //integratorThread.setPriority(Thread.MAX_PRIORITY);
        //System.err.println("" + generatorThread.getPriority() + " " + integratorThread.getPriority());
        generatorThread.start();
        integratorThread.start();
        try {
            Thread.sleep(50);
        } catch (InterruptedException ex) {
            System.err.println(ex);
        }
        generatorThread.interrupt();
        integratorThread.interrupt();
    }
}
TOP

Related Classes of Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.