sivasu.india@gmail.com schrieb:
> Hi,
>
[quoted text clipped - 24 lines]
> Regards,
> Siva
with synchronized keywords thats exactly what you do..
synchronized keyword in a method
is the same as
public void m2(){
synchronized(this) {
}
}
since only one thread can hold a monitor of an object only one thread
will be able to access your two methods.
Christian
Christian - 10 Apr 2007 13:57 GMT
Christian schrieb:
> sivasu.india@gmail.com schrieb:
>> Hi,
[quoted text clipped - 41 lines]
>
> Christian
sivasu.in...@gmail.com wrote per mail:
Hey , i think you have not understood the question clearly.
See it T1 is not accessing m1 means ,T2 can access m2.
if T1 is accessing m1 means,T2 should not access m2.
-----------------------------------
Please don't write me email ... post to the newsgroup
thats nearly what this synchronization here does..
while T1 accesses m1 or m2 , T2 will be unable to access m1 or m2
if this doesn't fit your needs...
then you should use the java.util.concurrent packet to do some more
appropriate locking...
For example Semaphores can be used for nearly any synchronization you
could imagine..
also with Thread.currentThread() you can obtain a reference to the
currently executing thread so if here would be a need for checking which
thread is currently accessing a method you can use this..
Christian