problem with threads

I have a class which has thread as its element. This thread is running continously. There is another method in same class which will be called ocassionaly by another class. Now when this method is invoked I have to stop thread which is running. I have done that by putting that particular thread to sleep inside the method. Even if the thread is put to sleep , performance is poor. i.e. even if thread is put to sleep , it continues running for some time and after that executes method which is invoked.

What could be the reason behind that? Is there any other way of doing that which will improve performance by transferring control directly to method and stopping thread execution for some time ?

[718 byte] By [vidula-kamat] at [2007-9-30 16:16:10]
# 1

Hi!

I didn齮 quite understand your sitation, but i am right?

You have object A.

object A contains this thread, which access object A's methods, and you want to stop thread, when you access A's method from outside from class?

That situation you can synchronize class a in method call.

class A {

public void test() {}

public void foo() {

synchronzied(this) {

// here class is synchronized, and thread cannot acces it until synchronzied block is finished.

test();

}

}

}

artsi1 at 2007-7-5 23:48:45 > top of Java-index,Administration Tools,Sun Connection...