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
What is number data type?
How do you add an arraylist to an array in java?
what is synchronization and why is it important? : Java thread
What is parse method?
What are variable arguments or varargs?
What are the different ways to handle exceptions?
What is 32 bit float?
Who is the owner of java?
Explain the difference between association, aggregation and inheritance relationships.
Is java same as core java?
What is the difference between length and length() method in java?
What is the largest number a double can hold?
how to handle exceptions in ejb?
What does the string method compareto () do?
What is local declaration?