Java Doc for Thread.java in  » 6.0-JDK-Modules » j2me » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.lang 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.lang.Thread

Thread
public class Thread implements Runnable(Code)
A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. For example, a thread that computes primes larger than a stated value could be written as follows:


 class PrimeThread extends Thread {
 long minPrime;
 PrimeThread(long minPrime) {
 this.minPrime = minPrime;
 }
 public void run() {
 // compute primes larger than minPrime
  . . .
 }
 }
 

The following code would then create a thread and start it running:

 PrimeThread p = new PrimeThread(143);
 p.start();
 

The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started. The same example in this other style looks like the following:


 class PrimeRun implements Runnable {
 long minPrime;
 PrimeRun(long minPrime) {
 this.minPrime = minPrime;
 }
 public void run() {
 // compute primes larger than minPrime
  . . .
 }
 }
 

The following code would then create a thread and start it running:

 PrimeRun p = new PrimeRun(143);
 new Thread(p).start();
 


version:
   12/17/01 (CLDC 1.1)
See Also:   java.lang.Runnable
See Also:   java.lang.Runtime.exit(int)
See Also:   java.lang.Thread.run
since:
   JDK1.0, CLDC 1.0



Field Summary
final public static  intMAX_PRIORITY
     The maximum priority that a thread can have.
final public static  intMIN_PRIORITY
     The minimum priority that a thread can have.
final public static  intNORM_PRIORITY
     The default priority that is assigned to a thread.

Constructor Summary
public  Thread()
     Allocates a new Thread object.
public  Thread(String name)
     Allocates a new Thread object with the given name.
public  Thread(Runnable target)
     Allocates a new Thread object with a specific target object whose run method is called.
public  Thread(Runnable target, String name)
     Allocates a new Thread object with the given target and name.

Method Summary
native public static  intactiveCount()
     Returns the current number of active threads in the virtual machine.
native public static  ThreadcurrentThread()
     Returns a reference to the currently executing Thread object.
final public  StringgetName()
     Returns this thread's name.
final public  intgetPriority()
     Returns this thread's priority.
public  voidinterrupt()
     Interrupts this thread.
final native public  booleanisAlive()
     Tests if this thread is alive.
final public synchronized  voidjoin()
     Waits for this thread to die.
exception:
  InterruptedException - if another thread has interruptedthe current thread.
public  voidrun()
     If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
final public  voidsetPriority(int newPriority)
     Changes the priority of this thread.
native public static  voidsleep(long millis)
     Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
public synchronized  voidstart()
     Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
public  StringtoString()
     Returns a string representation of this thread, including the thread's name and priority.
native public static  voidyield()
     Causes the currently executing thread object to temporarily pause and allow other threads to execute.

Field Detail
MAX_PRIORITY
final public static int MAX_PRIORITY(Code)
The maximum priority that a thread can have.



MIN_PRIORITY
final public static int MIN_PRIORITY(Code)
The minimum priority that a thread can have.



NORM_PRIORITY
final public static int NORM_PRIORITY(Code)
The default priority that is assigned to a thread.




Constructor Detail
Thread
public Thread()(Code)
Allocates a new Thread object.

Threads created this way must have overridden their run() method to actually do anything.
See Also:   java.lang.Runnable




Thread
public Thread(String name)(Code)
Allocates a new Thread object with the given name. Threads created this way must have overridden their run() method to actually do anything.
Parameters:
  name - the name of the new thread.



Thread
public Thread(Runnable target)(Code)
Allocates a new Thread object with a specific target object whose run method is called.
Parameters:
  target - the object whose run method is called.



Thread
public Thread(Runnable target, String name)(Code)
Allocates a new Thread object with the given target and name.
Parameters:
  target - the object whose run method is called.
Parameters:
  name - the name of the new thread.




Method Detail
activeCount
native public static int activeCount()(Code)
Returns the current number of active threads in the virtual machine. the current number of active threads.



currentThread
native public static Thread currentThread()(Code)
Returns a reference to the currently executing Thread object. the currently executing thread.



getName
final public String getName()(Code)
Returns this thread's name. Note that in CLDC the name of the thread can only be set when creating the thread. this thread's name.



getPriority
final public int getPriority()(Code)
Returns this thread's priority. this thread's priority.
See Also:   java.lang.Thread.setPriority(int)



interrupt
public void interrupt()(Code)
Interrupts this thread. In an implementation conforming to the CLDC Specification, this operation is not required to cancel or clean up any pending I/O operations that the thread may be waiting for.
since:
   JDK 1.0, CLDC 1.1



isAlive
final native public boolean isAlive()(Code)
Tests if this thread is alive. A thread is alive if it has been started and has not yet died. true if this thread is alive;false otherwise.



join
final public synchronized void join() throws InterruptedException(Code)
Waits for this thread to die.
exception:
  InterruptedException - if another thread has interruptedthe current thread. The interrupted status of thecurrent thread is cleared when this exception is thrown.



run
public void run()(Code)
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.
See Also:   java.lang.Thread.start
See Also:   java.lang.Runnable.run




setPriority
final public void setPriority(int newPriority)(Code)
Changes the priority of this thread.
Parameters:
  newPriority - priority to set this thread to
exception:
  IllegalArgumentException - If the priority is not in therange MIN_PRIORITY toMAX_PRIORITY.
See Also:   java.lang.Thread.getPriority
See Also:   java.lang.Thread.MAX_PRIORITY
See Also:   java.lang.Thread.MIN_PRIORITY



sleep
native public static void sleep(long millis) throws InterruptedException(Code)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
Parameters:
  millis - the length of time to sleep in milliseconds.
exception:
  InterruptedException - if another thread has interruptedthe current thread. The interrupted status of thecurrent thread is cleared when this exception is thrown.
See Also:   java.lang.Object.notify



start
public synchronized void start()(Code)
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).
exception:
  IllegalThreadStateException - if the thread was alreadystarted.
See Also:   java.lang.Thread.run




toString
public String toString()(Code)
Returns a string representation of this thread, including the thread's name and priority. a string representation of this thread.



yield
native public static void yield()(Code)
Causes the currently executing thread object to temporarily pause and allow other threads to execute.



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.