Native threads can switch between threads preemptively, switching control from a running thread to a non-running thread at any time. Green threads only switch when control is explicitly given up by a thread (Thread.yield(), Object.wait(), etc.) or a thread performs a blocking operation (read(), etc.). On multi-CPU machines, native threads can run more than one thread simultaneously by assigning different threads to different CPUs. Green threads run on only one CPU. Native threads create the appearance that many Java processes are running: each thread takes up its own entry in the process table. One clue that these are all threads of the same process is that the memory size is identical for all the threads - they are all using the same memory. Unfortunately, this behavior limits the scalability of Java on Linux. The process table is not infinitely large, and processes can only create a limited number of threads before running out of system resources or hitting configured limits.
In java we have two type of Threads : Daemon Thread and User Threads. Generally all threads created by programmer are user thread (unless you specify it to be daemon or your parent thread is a daemon thread). User thread are generally meant to run our programm code. JVM doesn't terminates unless all the user thread terminate.
On the other hand we have Daemon threads. Typically these threads are service provider threads. They should not be used to run your program code but some system code. These thread run paralley to your code but survive on the mercy of the JVM. When JVM finds no user threads it stops and all daemon thread terminate instantly. Thus one should never rely on daemon code to perform any program code.
For better understanding consider a well known example of Daemon thread : Java garbage collector. Garbage collector runs as a daemon thread to recalim any unused memory. When all user threads terminates, JVM may stop and garbage collector also terminates instantly.
two types of threads are there in java, they are background threads or system threads or service threads or daemon threads and user threads.
Daemon thread is one which executes at background and wastes all the resources.
In all situations try to utilize multithreading.
if you have single core server you will not get multithreading advantage.
If you have 4 core / 8 core processors then,
Identify all the sequential and concurrent computations.
based on number of cores, create those many threads and run.
mostly in heavy batch processing implement multi-threading.
Threads run inside process and they share data. One process can have multiple threads, if the process is killed all the threads inside it are killed, they dont share data
Synchronization is a technique to control the access of multiple threads to shared resources. Synchronization stops multithreading. With synchronization , at a time only one thread will be able to access a shared resource.
Synchronization is a process of controlling the access of shared resources by the multiple threads. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. The best example to learn this concept is to understand Producer Consumer problem.
Threads enters to waiting state or block on I/O because other threads can execute while the I/O operations are performed.
Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed.
By Monitor thread .
The main disadvantage of thread is that we need to synchronize the object while using the thread-deadlocks, data races, starvation are the main issues we need to consider-performance will be low because of synchronization.
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved