Home arrow Java & J2EE arrow Page 4 - More About Multithreading in Java

Taking a Break - Java

You are reading the second part of the multithreading in Java series. The first part covered the basics of threads, explained the theory that lies behind them, and then gave examples of the two possible ways of creating new threads. This article resumes the journey by getting even deeper into concepts like the ThreadGroup class, synchronization, and inter-thread communication.

  1. More About Multithreading in Java
  2. Stopping and Synchronization
  3. Inter-Thread Synchronization and Communication
  4. Taking a Break
By: Barzan "Tony" Antal
Rating: starstarstarstarstar / 16
March 04, 2009

print this article



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




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 & J2EE Articles          >>> More By Barzan "Tony" Antal

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: