synchronization: concurrent method access problem
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
.
Relevant Pages
- Re: File browser
... Any time you get your code to be called on the EDT, you are now in control. ... So it should be simple enough to write code that intentionally causes something to be called on the EDT, at which point one can take advantage of that control to ensure a synchronization error. ... Unfortunately, because it's specifically using invokeLaterto get code to execute on the EDT, it's not a demonstration of the problem I'm asking about. ... Before any components are shown, user actions won't affect when things are executed on the EDT. So, what of those "factors external to your application"? ... (comp.lang.java.programmer) - Re: Form freezing form
... >> When you update the form from the thread, are you taking care of the ... >> synchronization? ... updating the UI. ... (that basically contains the address of the function to execute) ... (microsoft.public.dotnet.languages.vc) - Re: Help on Asp.Net Code Syncronization
... I used SyncLock that works perfectly. ... Since each ASP.NET request is executed on a separate thread, you can take advantage of the .NET thread synchronization support. ... This is because this method execute some code that can't be execute twice at the same time. ... (microsoft.public.dotnet.framework.aspnet) - Re: Help on Asp.Net Code Syncronization
... Since each ASP.NET request is executed on a separate thread, you can take advantage of the .NET thread synchronization support. ... For synchronization within the same App Domain take a look at System.Threading.Monitor class or the syntactic sugar for this in C# is lock and SyncLock in VB.NET ... This is because this method execute some code that can't be execute twice at the same time. ... (microsoft.public.dotnet.framework.aspnet) - Re: autoexec.nt elusive
... I want to invoke a clock synchronization scheme to NIST, ... invoke "net start w32time" upon start up... ... of periodic synchronization: nistime-32bit.exe. ... Why do you want to execute it? ... (microsoft.public.win2000.general) |
|