Can an body explain alternate way to achieve the threadsafe without using the synchronization at method level block level?
public synchronized int disp()
{
}
or
public int disp()
{
Synchronized
{}
}
Can an body explain alternate way to achieve the threadsafe without using the synchronization at method level block level?
public synchronized int disp()
{
}
or
public int disp()
{
Synchronized
{}
}
You could just use a single thread, of course.
You can design your application to avoid sharing mutable state, so that methods are inherently threadsafe.
You can use synchronized library collections.
You can use threadsafe queues to communicate between threads (Concurrent Queues).
It rather depends on what you are trying to achieve...
There is another variant called Class Level Synchronization
. But it is a kind of Block level synchronization only.
But, before that can you explain in your question why is such requirement?