Bureaucrats, cc_docs_admin, cc_staff
2,306
edits
Line 4: | Line 4: | ||
===Threading=== | ===Threading=== | ||
Java includes built-in support for threading, obviating the need for separate interfaces and libraries like OpenMP, pthreads and Boost threads used in other languages. The principal Java object for handling concurrency is the <tt>Thread</tt> class which a programmer can use by either providing a <tt>Runnable</tt> method to the standard <tt>Thread</tt> class or by subclassing the <tt>Thread</tt> class. | Java includes built-in support for threading, obviating the need for separate interfaces and libraries like OpenMP, pthreads and Boost threads used in other languages. The principal Java object for handling concurrency is the <tt>Thread</tt> class which a programmer can use by either providing a <tt>Runnable</tt> method to the standard <tt>Thread</tt> class or by subclassing the <tt>Thread</tt> class. As an example of this second approach, consider the following toy program: | ||
{{File | |||
|name=thread.java | |||
|lang="Java" | |||
|contents= | |||
public class HelloWorld extends Thread { | |||
public void run() { | |||
System.out.println("Hello World!"); | |||
} | |||
public static void main(String args[]) { | |||
(new HelloWorld()).start(); | |||
} | |||
} | |||
}} | |||
This second approach is generally the simplest to use but suffers from the drawback that Java does not permit multiple inheritance, so the class which implements multithreading wouldn't be able to subclass any other, potentially more useful, class. | |||
===MPI and Java=== | ===MPI and Java=== |