How multi processing is achieved in JAVA?

Answer Posted / javalearner

An operating system executes multiple processes in a manner similar to that for multi-threading, except that each process stack refers to a different program in memory rather than code within a single program. The Java Virtual Machine (JVM), of course, controls the threading within the Java programs, just as the machine OS controls multiple processes.

In some JVM designs, threads can be assigned to native kernel processes in the OS. Furthermore, for operating systems such as Solaris and Windows NT that can control multiple processors, the threads can actually run on different processors and thus provide true parallel processing performance.

Whether its for multithreading or multiprocessing, the two basic designs for this context switching, i.e. the shifting of threads/processes in and out of a processor, include

preemptive or time-slicing - give each thread a fixed amount of time.

non-preemptive or cooperative - a thread decides itself when to surrender control
Generally, the preemptive approach is the most flexible and robust. A misbehaving thread cannot hog all the resources or hang the processor. Unfortunately, the context switching is not specified for Java and so different JVM implementations do it differently. Thus you should design your multi-threaded code for either possibility if you want it to be suitable for broad distribution. This means adding yield()or sleep() calls to release control at suitable points in the thread code.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is bmg file and how to create that files?what will it contailn?

2149


How can we make sure main() is the last thread to finish in java program?

946


What is immutability in java?

823


What is the final blank variable?

822


Is null function in java?

788


What are the object and class classes used for?

800


Is object a data type?

759


Write a program to check string is palindrome without using loop?

789


How do you sing an Applet ?

2246


Is zero a natural number?

780


Can we have any other return type than void for main method?

757


What is a lightweight component?

809


How to make a non daemon thread as daemon?

810


What is the purpose of the finalize() method?

956


Which data type is a class in java?

775