Package thread.concurrencyCookbook.chapter4.recipe6

Examples of thread.concurrencyCookbook.chapter4.recipe6.Task


  @Test
  public void testUpdate() throws Exception {
    XmlObject xmlObject = XmlObject.Factory.parse(this.getClass().getResource("/update.xml"));
    Assert.assertNotNull(xmlObject);
        System.out.println(xmlObject.toString());
        Task taskElement = Task.Factory.newInstance();
        TaskMetadata metadata = taskElement.addNewMetadata();
       
        metadata.set(new TaskUnmarshaller().expectElement(xmlObject, "taskMetadata"));
        System.out.println(taskElement.getMetadata().getTaskId());
  }
View Full Code Here


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

    // Creates and starts a DataSourceLoader runnable object
    DataSourcesLoader dsLoader = new DataSourcesLoader();
    Thread thread1 = new Thread(dsLoader,"DataSourceThread");
    thread1.start();

    // Creates and starts a NetworkConnectionsLoader runnable object
    NetworkConnectionsLoader ncLoader = new NetworkConnectionsLoader();
View Full Code Here

    DataSourcesLoader dsLoader = new DataSourcesLoader();
    Thread thread1 = new Thread(dsLoader,"DataSourceThread");
    thread1.start();

    // Creates and starts a NetworkConnectionsLoader runnable object
    NetworkConnectionsLoader ncLoader = new NetworkConnectionsLoader();
    Thread thread2 = new Thread(ncLoader,"NetworkConnectionLoader");
    thread2.start();

    // Wait for the finalization of the two threads
    try {
View Full Code Here

    FileMock mock=new FileMock(101, 10);
   
    /**
     * Creates a buffer with a maximum of 20 lines
     */
    Buffer buffer=new Buffer(20);
   
    /**
     * Creates a producer and a thread to run it
     */
    Producer producer=new Producer(mock, buffer);
View Full Code Here

    Thread threadProducer=new Thread(producer,"Producer");
   
    /**
     * Creates three consumers and threads to run them
     */
    Consumer consumers[]=new Consumer[3];
    Thread threadConsumers[]=new Thread[3];
   
    for (int i=0; i<3; i++){
      consumers[i]=new Consumer(buffer);
      threadConsumers[i]=new Thread(consumers[i],"Consumer "+i);
    }
   
    /**
     * Strats the producer and the consumers
View Full Code Here

    Buffer buffer=new Buffer(20);
   
    /**
     * Creates a producer and a thread to run it
     */
    Producer producer=new Producer(mock, buffer);
    Thread threadProducer=new Thread(producer,"Producer");
   
    /**
     * Creates three consumers and threads to run them
     */
 
View Full Code Here

   */
  public static void main(String[] args) {
    /**
     * Creates a simulated file with 100 lines
     */
    FileMock mock=new FileMock(101, 10);
   
    /**
     * Creates a buffer with a maximum of 20 lines
     */
    Buffer buffer=new Buffer(20);
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {
   
    // Creates the Phaser
    MyPhaser phaser=new MyPhaser();
   
    // Creates 5 students and register them in the phaser
    Student students[]=new Student[5];
    for (int i=0; i<students.length; i++){
      students[i]=new Student(phaser);
      phaser.register();
    }
   
    // Create 5 threads for the students and start them
    Thread threads[]=new Thread[students.length];
    for (int i=0; i<students.length; i++) {
      threads[i]=new Thread(students[i],"Student "+i);
      threads[i].start();
    }
   
    // Wait for the finalization of the threads
    for (int i=0; i<threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
   
    // Check that the Phaser is in the Terminated state
    System.out.printf("Main: The phaser has finished: %s.\n",phaser.isTerminated());
   
  }
View Full Code Here

   
    // Creates the Phaser
    MyPhaser phaser=new MyPhaser();
   
    // Creates 5 students and register them in the phaser
    Student students[]=new Student[5];
    for (int i=0; i<students.length; i++){
      students[i]=new Student(phaser);
      phaser.register();
    }
   
    // Create 5 threads for the students and start them
    Thread threads[]=new Thread[students.length];
View Full Code Here

    // Writes the results to the console
    System.out.printf("Core: Printing the results\n");
    for (int i=0; i<resultList.size(); i++){
      Future<Result> future=resultList.get(i);
      try {
        Result result=future.get();
        System.out.printf("%s: %s\n",result.getName(),result.getValue());
      } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
      }
    }
  }
View Full Code Here

TOP

Related Classes of thread.concurrencyCookbook.chapter4.recipe6.Task

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.