Java
  Home arrow Java arrow Page 4 - More About Multithreading in Java
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

More About Multithreading in Java
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2009-03-04


    Table of Contents:
  • More About Multithreading in Java
  • Stopping and Synchronization
  • Inter-Thread Synchronization and Communication
  • Taking a Break

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    More About Multithreading in Java - Taking a Break
    ( Page 4 of 4 )

     

    As you can see, we have arrived at the end of this sequel article. By now you should know how to work with multiple threads, create them, make them share data and variables between each other, synchronize attributes, manage their states, and make them communicate between each other. 

    Before we finish, there are two more interesting types of classes regarding threads that we should mention. These are the Timer Class and the TimerTask Class. With the help of these we can schedule some parts of our program. Basically, the scheduled task will be run as a separate thread (like a background thread) when its appropriate time arrives. As a rule of thumb, these timer tasks should be quick, otherwise they might hog and/or speed up (since the task was delayed) the application execution. 

    Here’s a really quick example; please complete the snippet with the required parts.

     

    class Scheduler{

    Timer timer;

     

    public Scheduler(int seconds){

    timer = new Timer();

    timer.schedule(new RemindTask(), seconds*1000);

    }

     

    class RemindTask extends TimerTask{

    public void run(){

    System.out.println(" Boo! "); // this is the actual task

    timer.cancel();

    }

    }

    Thanks for following this series; hopefully, you’ve found it educational. We welcome and appreciate all kinds of feedback in the blog comment section below; thus, feel free to write your opinion, ask questions, and we'll clarify your dilemmas. 

    In closing, I’d like to invite you to join our experienced community of technology professionals on all areas of IT&C starting from software and hardware up to consumer electronics at Dev Hardware Forums. Also, be sure to check out the community of our sister site at Dev Shed Forums. We are friendly and we’ll do our best to help you.



     
     
    >>> More Java Articles          >>> More By Barzan "Tony" Antal
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek