V
V
Vadim Gush2014-05-16 14:51:47
Java
Vadim Gush, 2014-05-16 14:51:47

How to do two cycles at the same time

Faced such a problem that two loops in Java would work simultaneously. How to do it? (while(){} loops)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Smith, 2014-05-16
@VadimGu

Thread

D
dginz, 2014-05-17
@dginz

You need a multi-threaded application. There are quite a few options for how to run multiple threads at the same time. Simplest:

Thread thread1 = new Thread(new Runnable() {
    public void run() {
        while (....)
            ....
    }
});
Thread thread2 = new Thread(new Runable() {
    public void run() {
        while (....)
            ....
    }
});
thread1.start();
thread2.start();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question