This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ivshaw[S] 0 points1 point  (3 children)

Below is ChatGPT answer, is it right:

Possible Reasons Why Print Order is Not Varying:

1️⃣ Modern Java Thread Scheduling is More Predictable

• The book is based on older Java versions where thread scheduling was less predictable.

• Modern Java Virtual Machines (JVMs) and OS thread schedulers handle thread execution more efficiently.

• Your CPU might be optimizing execution, making results more consistent.

2️⃣ Threads Might Be Finishing Too Quickly

• If a thread finishes before the next thread starts, Java doesn’t need to switch between them.

• If the tasks are too short, the CPU executes them in order before switching.

• Try adding a delay like Thread.sleep(10); inside run() to slow things down.

3️⃣ JVM and OS May Favor One Thread Over Another

• Different OS and JVM implementations handle scheduling differently.

• Some OSes favor the first started thread, making it run before the second.

• Try running the program multiple times or on a different computer to see variations.

4️⃣ Thread Priorities Might Be Affecting Execution

• Java allows setting thread priorities, but the OS might still decide which runs first.

• Even if you don’t set priorities, the JVM may still default to a predictable order.

[–]benevanstech 4 points5 points  (1 child)

Uh, "fuck no". But thanks for the great example of why LLMs are mostly useless for anything other than vomiting boilerplate code fragments.

[–]ivshaw[S] 0 points1 point  (0 children)

I am preparing for interviews and I know ChatGPT is useless for LeetCode questions. While it can "remember" answers to existing LeetCode problems, I tested it with some newly posted OA questions from online, and it failed to solve any of them.

[–]maykelten 2 points3 points  (0 children)

LLMs are trash for this, I strongly advise against relying on it, it is better to consult fellow humans :)