Tom
Tom

Reputation: 8127

Does the Java Robot class run in its own thread?

In the Robot documentation I don't see anything about Robot extending Thread. However, I am sure I have heard people say that the Robot runs in its own thread.

So, does each instance of Robot run in its own thread, do all robot instances run in one thread, or do they all simply run in the current thread?

Upvotes: 2

Views: 2336

Answers (1)

WhiteFang34
WhiteFang34

Reputation: 72049

The Robot class runs in the current thread. There's nothing in the source that starts a Thread. You can verify it easily enough too, just run this in Eclipse and look at the threads in Debug view:

List<Robot> robots = new ArrayList<Robot>();
for (int i = 0; i < 10; i++) {
    robots.add(new Robot());
}
Thread.sleep(60000);

Upvotes: 3

Related Questions