From 71517ef506039ffd16ce92ff4c82e13293c879d6 Mon Sep 17 00:00:00 2001 From: ZahraSadatMirvakili Date: Wed, 3 Jun 2026 00:17:08 +0330 Subject: [PATCH] redmi2 + multithreading --- Report.md | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Report.md b/Report.md index 3abf6e5..9e71b1f 100644 --- a/Report.md +++ b/Report.md @@ -7,10 +7,13 @@ ## 1. start() vs run() ### Output: --Calling run() --Running in: main --Calling start() --Running in: Thread-2 +Calling run() + +Running in: main + +Calling start() + +Running in: Thread-2 ### Explanation When calling "t1.run()" directly, the run method executes in the current thread (main). @@ -30,24 +33,28 @@ When calling "t2.start()" , java creates a new thread and executes run() in that ### Output(with demon): --Main thread ends --Deamon thread running... --(Program terminates quickly) +Main thread ends + +Deamon thread running... + +(Program terminates quickly) ### Output(without demon): --Main thread ends. --Deamon thread running... --(20 times) +Main thread ends. + +Deamon thread running... + +(20 times) ### Explanation --A daemon thread is a background thread that does NOT prevent the JVM from exiting. +A daemon thread is a background thread that does NOT prevent the JVM from exiting. When the main thread (non-daemon) finishes, the JVM checks if there are any non-daemon threads still running. Since only the daemon thread remains, the JVM terminates immediately without waiting for the daemon thread to complete its 20 iterations. --Without setDaemon(true), the thread becomes a user thread (non-daemon) . +Without setDaemon(true), the thread becomes a user thread (non-daemon) . User threads prevent the JVM from exiting until they complete. Therefore, the JVM waits for the thread to finish all 20 iterations before terminating the program. @@ -65,7 +72,7 @@ Therefore, the JVM waits for the thread to finish all 20 iterations before termi ### Output: --Thread is running using a...! +Thread is running using a...! ### What is `() -> {}`? This is a **Lambda Expression** introduced in Java.