Package com.packtpub.java7.concurrency.chapter1.recipe7.task

Examples of com.packtpub.java7.concurrency.chapter1.recipe7.task.WriterTask


   */
  public static void main(String[] args) {

    //Launch 10 threads that make the operation with a different number
    for (int i=1; i<=10; i++){
      Calculator calculator=new Calculator(i);
      Thread thread=new Thread(calculator);
      thread.start();
    }
  }
View Full Code Here


   */
  public static void main(String[] args) {

    // Create a ThreadGroup
    ThreadGroup threadGroup = new ThreadGroup("Searcher");
    Result result=new Result();

    // Create a SeachTask and 10 Thread objects with this Runnable
    SearchTask searchTask=new SearchTask(result);
    for (int i=0; i<5; i++) {
      Thread thread=new Thread(threadGroup, searchTask);
View Full Code Here

    // Create a ThreadGroup
    ThreadGroup threadGroup = new ThreadGroup("Searcher");
    Result result=new Result();

    // Create a SeachTask and 10 Thread objects with this Runnable
    SearchTask searchTask=new SearchTask(result);
    for (int i=0; i<5; i++) {
      Thread thread=new Thread(threadGroup, searchTask);
      thread.start();
      try {
        TimeUnit.SECONDS.sleep(1);
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {

    // Create a MyThreadGroup object
    MyThreadGroup threadGroup=new MyThreadGroup("MyThreadGroup");
    // Create a Taks object
    Task task=new Task();
    // Create and start two Thread objects for this Task
    for (int i=0; i<2; i++){
      Thread t=new Thread(threadGroup,task);
View Full Code Here

  public static void main(String[] args) {

    // Create a MyThreadGroup object
    MyThreadGroup threadGroup=new MyThreadGroup("MyThreadGroup");
    // Create a Taks object
    Task task=new Task();
    // Create and start two Thread objects for this Task
    for (int i=0; i<2; i++){
      Thread t=new Thread(threadGroup,task);
      t.start();
    }
View Full Code Here

   * ten Thread objects using that Factory
   * @param args
   */
  public static void main(String[] args) {
    // Creates the factory
    MyThreadFactory factory=new MyThreadFactory("MyThreadFactory");
    // Creates a task
    Task task=new Task();
    Thread thread;
   
    // Creates and starts ten Thread objects
    System.out.printf("Starting the Threads\n");
    for (int i=0; i<10; i++){
      thread=factory.newThread(task);
      thread.start();
    }
    // Prints the statistics of the ThreadFactory to the console
    System.out.printf("Factory stats:\n");
    System.out.printf("%s\n",factory.getStats());
   
  }
View Full Code Here

   */
  public static void main(String[] args) {
    // Creates the factory
    MyThreadFactory factory=new MyThreadFactory("MyThreadFactory");
    // Creates a task
    Task task=new Task();
    Thread thread;
   
    // Creates and starts ten Thread objects
    System.out.printf("Starting the Threads\n");
    for (int i=0; i<10; i++){
View Full Code Here

    // Launch 10 threads to do the operation, 5 with the max
    // priority, 5 with the min
    threads=new Thread[10];
    status=new Thread.State[10];
    for (int i=0; i<10; i++){
      threads[i]=new Thread(new Calculator(i));
      if ((i%2)==0){
        threads[i].setPriority(Thread.MAX_PRIORITY);
      } else {
        threads[i].setPriority(Thread.MIN_PRIORITY);
      }
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {

    // Launch the prime numbers generator
    Thread task=new PrimeGenerator();
    task.start();
   
    // Wait 5 seconds
    try {
      TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Interrupt the prime number generator
    task.interrupt();
  }
View Full Code Here

   * and then, interrupts the Thread
   * @param args
   */
  public static void main(String[] args) {
    // Creates the Runnable object and the Thread to run it
    FileSearch searcher=new FileSearch("C:\\","autoexec.bat");
    Thread thread=new Thread(searcher);
   
    // Starts the Thread
    thread.start();
   
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter1.recipe7.task.WriterTask

Copyright © 2018 www.massapicom. 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.