P
Piper707
Hi,
I have a problem for a bit of code that needs thread synchronization.
The code is something like this:
classA
{
static synchronized getUniqueId()
}
class B
{
A.getUniqueId()
}
I have a class A that contains a static synchronized method that
assigns unique ids. This method gets invoked from a different class
and by multiple threads.
Multiple threads did enter the same method inspite of the synchronized
keyword, and this resulted in the same id being given to different
threads.
I found a post that explains that Two threads can execute the same
synchronized method on
different instances concurrently.
Keeping that in mind, I could think of two options:
1) make class A singleton, so that all the threads try to execute the
same synchronized method on a single instance
2) make class A a static member variable in class B and invoke the
call as it is currently done.
is this the right approach? am I on the right track here?
thanks for any help,
Rohit
I have a problem for a bit of code that needs thread synchronization.
The code is something like this:
classA
{
static synchronized getUniqueId()
}
class B
{
A.getUniqueId()
}
I have a class A that contains a static synchronized method that
assigns unique ids. This method gets invoked from a different class
and by multiple threads.
Multiple threads did enter the same method inspite of the synchronized
keyword, and this resulted in the same id being given to different
threads.
I found a post that explains that Two threads can execute the same
synchronized method on
different instances concurrently.
Keeping that in mind, I could think of two options:
1) make class A singleton, so that all the threads try to execute the
same synchronized method on a single instance
2) make class A a static member variable in class B and invoke the
call as it is currently done.
is this the right approach? am I on the right track here?
thanks for any help,
Rohit