Very simple Threading example. : Simple Threads « Threads « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Threads » Simple ThreadsScreenshots 
Very simple Threading example.
Very simple Threading example.


//: c13:SimpleThread.java
// Very simple Threading example.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

public class SimpleThread extends Thread {
  private int countDown = 5;
  private static int threadCount = 0;
  public SimpleThread() {
    super("" + ++threadCount)// Store the thread name
    start();
  }
  public String toString() {
    return "#" + getName() ": " + countDown;
  }
  public void run() {
    while(true) {
      System.out.println(this);
      if(--countDown == 0return;
    }
  }
  public static void main(String[] args) {
    for(int i = 0; i < 5; i++)
      new SimpleThread();
  }
///:~


           
       
Related examples in the same category
1. Thread ReminderThread Reminder
2. Thread Race DemoThread Race Demo
3. Suggesting when to switch threads with yield()Suggesting when to switch threads with yield()
4. Creating threads with inner classesCreating threads with inner classes
5. The safe way to stop a thread
6. Calling sleep() to wait for a whileCalling sleep() to wait for a while
7. Understanding join()Understanding join()
8. Daemon threads spawn other daemon threadsDaemon threads spawn other daemon threads
9. Daemon threads don't prevent the program from ending.
10. Shows the use of thread priorities.Shows the use of thread priorities.
11. Java new feature: threadingJava new feature: threading
12. Java 1.5 (5.0) new feature: Thread ScheduleJava 1.5 (5.0) new feature: Thread Schedule
13. Two simple threadsTwo simple threads
14. Simple threads creator Simple threads creator
15. Task
16. SimpleThread using the Runnable interface.SimpleThread using the Runnable interface.
17. Test Override ThreadTest Override Thread
18. Test Override
19. Parallelizing Loops for Multiprocessor Machines
20. Three Threads TestThree Threads Test
w_w___w___.__ja_va___2_s__.__c__o__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.