Answer the question
In order to leave comments, you need to log in
How to access a method in order?
public class SeleniumBufferead implements Runnable {
private void send() throws Exception{
//Тут ещё другой код коонечно
sendMessages.send("каккие-то числа", "Сообщение");
Thread.sleep(1000000);
}
@Override
public void run() {
try {
this.send();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Answer the question
In order to leave comments, you need to log in
synchronized method is synchronized on this. Won't fit. For example, you can pass everywhere the object on which you want to synchronize.
public class SeleniumBufferead implements Runnable {
private final Object lock;
public SeleniumBufferead(Object lock) {
this.lock = lock;
}
private void send() {
synchronized(lock) {
//code
}
}
}
.....
final Object lock = new Object();
new Thread(new SeleniumBufferead(lock)).start();
new Thread(new SeleniumBufferead(lock)).start();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question