Arun
Arun

Reputation: 1789

Change in synchronised thread execution order

I am executing a java-synchronisation example:

Thread call code:

Caller ob1 = new Caller(target, "Hello");
Caller ob2 = new Caller(target, "Synchronized");
Caller ob3 = new Caller(target, "World");

Output:

[Hello]
[World]
[Synchronized]

Why does "Synchronized" gets printed last, though it's called in 2nd?

Upvotes: 0

Views: 104

Answers (1)

setzamora
setzamora

Reputation: 3640

There's no guarantee in the order of execution. It is the discretion of the JVM.

Invoking the start() method of a Thread instance doesn't guarantee that it will run after the method call right away.

Upvotes: 1

Related Questions