Package thread.concurrencyCookbook.chapter1.recipe1.task

Examples of thread.concurrencyCookbook.chapter1.recipe1.task.Calculator


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


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

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Creates a new account ...
    Account  account=new Account();
    // an initialize its balance to 1000
    account.setBalance(1000);
   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
    // Prints the initial balance
    System.out.printf("Account : Initial Balance: %f\n",account.getBalance());
   
    // Starts the Threads
    companyThread.start();
    bankThread.start();

    try {
      // Wait for the finalization of the Threads
      companyThread.join();
      bankThread.join();
      // Print the final balance
      System.out.printf("Account : Final Balance: %f\n",account.getBalance());
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Creates a new account ...
    Account  account=new Account();
    // an initialize its balance to 1000
    account.setBalance(1000);
   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
    // Prints the initial balance
    System.out.printf("Account : Initial Balance: %f\n",account.getBalance());
   
    // Starts the Threads
    companyThread.start();
    bankThread.start();

    try {
      // Wait for the finalization of the Threads
      companyThread.join();
      bankThread.join();
      // Print the final balance
      System.out.printf("Account : Final Balance: %f\n",account.getBalance());
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
    // Prints the initial balance
    System.out.printf("Account : Initial Balance: %f\n",account.getBalance());
   
View Full Code Here

   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
    // Prints the initial balance
    System.out.printf("Account : Initial Balance: %f\n",account.getBalance());
   
View Full Code Here

    Account  account=new Account();
    // an initialize its balance to 1000
    account.setBalance(1000);
   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
View Full Code Here

    Account  account=new Account();
    // an initialize its balance to 1000
    account.setBalance(1000);
   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
View Full Code Here

    PrintQueue printQueue=new PrintQueue();
   
    // Creates ten Threads
    Thread thread[]=new Thread[10];
    for (int i=0; i<10; i++){
      thread[i]=new Thread(new Job(printQueue),"Thread "+i);
    }
   
    // Starts the Threads
    for (int i=0; i<10; i++){
      thread[i].start();
View Full Code Here

   * send documents to the print queue at the same time.
   */
  public static void main (String args[]){
   
    // Creates the print queue
    PrintQueue printQueue=new PrintQueue();
   
    // Creates ten Threads
    Thread thread[]=new Thread[10];
    for (int i=0; i<10; i++){
      thread[i]=new Thread(new Job(printQueue),"Thread "+i);
View Full Code Here

TOP

Related Classes of thread.concurrencyCookbook.chapter1.recipe1.task.Calculator

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.