- subj. question makes little sense to me, how can a Thread invoke two methods simultaneously??? As far as I know there's no way to do that. It's possible, however, to call an asynchronous method (like start() in Thread, which is btw is not synchronized, but could be as well) which doesn't block and upon return from this call invoke another synchronized method. In other words, you need to have two threads running in this case. In general, you cannot run two methods (synchronized or not) simultaneously on the same thread. Give more details if this is not what you wanted to know.
- Yes, a thread can obtain a lock on an object:
<pre>
Object o = new SomeClass();
synchronized(o) { // do something }
</pre>
- No, there's no method level locks in Java, but you can play tricks like (quick guess, tell me if wrong...):
<pre>
class X
{
public static final byte[] lock = new byte[0];
public synchronized void m()
{
synchronized (lock)
{
// do something
}
}
}
class Y
{
public void foo()
{
synchronized (X.lock) //need to do smthng before calling m()
{
// ... do things
X x = new X();
x.m();
}
}
}
</pre>
regards,
VG.
[This message has been edited by Vlad G (edited January 01, 2001).]