Examples of Task


Examples of com.packtpub.java7.concurrency.chapter1.recipe11.task.Task

  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

Examples of com.packtpub.java7.concurrency.chapter1.recipe12.task.Task

   */
  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

Examples of com.packtpub.java7.concurrency.chapter1.recipe8.task.Task

   * exception
   * @param args
   */
  public static void main(String[] args) {
    // Creates the Task
    Task task=new Task();
    // Creates the Thread
    Thread thread=new Thread(task);
    // Sets de uncaugh exceptio handler
    thread.setUncaughtExceptionHandler(new ExceptionHandler());
    // Starts the Thread
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe1.task.Task

    // Create the server
    Server server=new Server();
   
    // Send 100 request to the server and finish
    for (int i=0; i<100; i++){
      Task task=new Task("Task "+i);
      server.executeTask(task);
    }
   
    server.endServer();
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe12.task.Task

    executor.setRejectedExecutionHandler(controller);
   
    // Lauch three tasks
    System.out.printf("Main: Starting.\n");
    for (int i=0; i<3; i++) {
      Task task=new Task("Task"+i);
      executor.submit(task);
    }
   
    // Shutdown the executor
    System.out.printf("Main: Shuting down the Executor.\n");
    executor.shutdown();

    // Send another task
    System.out.printf("Main: Sending another Task.\n");
    Task task=new Task("RejectedTask");
    executor.submit(task);
   
    // The program ends
    System.out.printf("Main: End.\n");
   
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe4.task.Task

    FileSearch system=new FileSearch("C:\\Windows", "log");
    FileSearch apps=new FileSearch("C:\\Program Files","log");
    FileSearch documents=new FileSearch("C:\\Documents And Settings","log");
   
    // Create three Task objects
    Task systemTask=new Task(system,null);
    Task appsTask=new Task(apps,null);
    Task documentsTask=new Task(documents,null);
   
    // Submit the Tasks to the Executor
    executor.submit(systemTask);
    executor.submit(appsTask);
    executor.submit(documentsTask);
   
    // Shutdown the executor and wait for the end of the tasks
    executor.shutdown();
    try {
      executor.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Write to the console the number of results
    try {
      System.out.printf("Main: System Task: Number of Results: %d\n",systemTask.get().size());
      System.out.printf("Main: App Task: Number of Results: %d\n",appsTask.get().size());
      System.out.printf("Main: Documents Task: Number of Results: %d\n",documentsTask.get().size());
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (ExecutionException e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe6.task.Task

    ExecutorService executor=(ExecutorService)Executors.newCachedThreadPool();

    // Create three tasks and stores them in a List
    List<Task> taskList=new ArrayList<>();
    for (int i=0; i<3; i++){
      Task task=new Task("Task-"+i);
      taskList.add(task);
    }

    // Call the invokeAll() method
    List<Future<Result>>resultList=null;
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe7.task.Task

   
    System.out.printf("Main: Starting at: %s\n",new Date());
   
    // Send the tasks to the executor with the specified delay
    for (int i=0; i<5; i++) {
      Task task=new Task("Task "+i);
      executor.schedule(task,i+1 , TimeUnit.SECONDS);
    }
   
    // Finish the executor
    executor.shutdown();
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe8.task.Task

    ScheduledExecutorService executor=Executors.newScheduledThreadPool(1);
    System.out.printf("Main: Starting at: %s\n",new Date());

    // Create a new task and sends it to the executor. It will start with a delay of 1 second and then
    // it will execute every two seconds
    Task task=new Task("Task");
    ScheduledFuture<?> result=executor.scheduleAtFixedRate(task, 1, 2, TimeUnit.SECONDS);
   
    // Controlling the execution of tasks
    for (int i=0; i<10; i++){
      System.out.printf("Main: Delay: %d\n",result.getDelay(TimeUnit.MILLISECONDS));
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter4.recipe9.task.Task

   
    // Create an executor
    ThreadPoolExecutor executor=(ThreadPoolExecutor)Executors.newCachedThreadPool();
   
    // Create a task
    Task task=new Task();
   
    System.out.printf("Main: Executing the Task\n");

    // Send the task to the executor
    Future<String> result=executor.submit(task);
View Full Code Here
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.