Package com.packtpub.java7.concurrency.chapter2.recipe2.core

Examples of com.packtpub.java7.concurrency.chapter2.recipe2.core.Main


   * 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

   * @param args
   */
  public static void main(String[] args) {
   
    // Create a new object for the statistics
    BuildStats stats=new BuildStats();

    // Create a Sensor1 object and a Thread to run it
    Sensor1 sensor1=new Sensor1(stats);
    Thread thread1=new Thread(sensor1,"Sensor 1");

    // Create a Sensor 2 object and a Thread to run it
    Sensor2 sensor2=new Sensor2(stats);
    Thread thread2=new Thread(sensor2,"Sensor 2");
   
    // Get the actual time
    Date date1=new Date();
   
    //Starts the threads
    thread1.start();
    thread2.start();
   
    try {
      // Wait for the finalization of the threads
      thread1.join();
      thread2.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    //Get the actual time and print the execution time
    Date date2=new Date();
    stats.printStats();
    System.out.println("Execution Time: "+((date2.getTime()-date1.getTime())/1000));

  }
View Full Code Here

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Creates a Cinema
    Cinema cinema=new Cinema();
   
    // Creates a TicketOffice1 and a Thread to run it
    TicketOffice1 ticketOffice1=new TicketOffice1(cinema);
    Thread thread1=new Thread(ticketOffice1,"TicketOffice1");

    // Creates a TicketOffice2 and a Thread to run it
    TicketOffice2 ticketOffice2=new TicketOffice2(cinema);
    Thread thread2=new Thread(ticketOffice2,"TicketOffice2");
   
    // Starts the threads
    thread1.start();
    thread2.start();
   
    try {
      // Waits for the finalization of the threads
      thread1.join();
      thread2.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // Print the vacancies in the cinemas
    System.out.printf("Room 1 Vacancies: %d\n",cinema.getVacanciesCinema1());
    System.out.printf("Room 2 Vacancies: %d\n",cinema.getVacanciesCinema2());
  }
View Full Code Here

    // Creates a Producer and a Thread to run it
    Producer producer=new Producer(storage);
    Thread thread1=new Thread(producer);

    // Creates a Consumer and a Thread to run it
    Consumer consumer=new Consumer(storage);
    Thread thread2=new Thread(consumer);
   
    // Starts the thread
    thread2.start();
    thread1.start();
View Full Code Here

   * Main method of the example
   */
  public static void main(String[] args) {
   
    // Creates an event storage
    EventStorage storage=new EventStorage();
   
    // Creates a Producer and a Thread to run it
    Producer producer=new Producer(storage);
    Thread thread1=new Thread(producer);

View Full Code Here

   
    // Creates an event storage
    EventStorage storage=new EventStorage();
   
    // Creates a Producer and a Thread to run it
    Producer producer=new Producer(storage);
    Thread thread1=new Thread(producer);

    // Creates a Consumer and a Thread to run it
    Consumer consumer=new Consumer(storage);
    Thread thread2=new Thread(consumer);
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter2.recipe2.core.Main

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.