Package com.packtpub.java7.concurrency.chapter2.recipe4.task

Examples of com.packtpub.java7.concurrency.chapter2.recipe4.task.Writer


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

   * 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

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

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Creates a task
    SafeTask task=new SafeTask();
   
    // Creates and start three Thread objects for that Task
    for (int i=0; i<3; i++){
      Thread thread=new Thread(task);
      try {
View Full Code Here

   * three Thread objects that run it.
   * @param args
   */
  public static void main(String[] args) {
    // Creates the unsafe task
    UnsafeTask task=new UnsafeTask();
   
    // Throw three Thread objects
    for (int i=0; i<3; i++){
      Thread thread=new Thread(task);
      thread.start();
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

TOP

Related Classes of com.packtpub.java7.concurrency.chapter2.recipe4.task.Writer

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.