Run parallel code snippets

0

Hello, I wanted to know how to execute one thread after another for a certain time, for example:

Thread x = new Thread(() -> {
// qualquer código, pode ter até um while(true)...
});
Thread x2 = new Thread(() -> {
// qualquer código, pode ter até um while(true)...
});

I have a thread x that should run for 3s, after that time it should pause and then x2 should start, but it can not contain any additional code inside its runnable. Thank you in advance.

    
asked by anonymous 11.06.2017 / 22:46

1 answer

-1

Dear colleague,

The best in this case is to create a class that inherits Thread and implement the run () {} method. This method you can put a synchronized method in that way, when you can call the start method and to pause only call the sleep method, passing in the parameter the time you need it to wait.

    
12.06.2017 / 00:08