From d1c3e552a018df7aaf2160367b0e6ecfd058ec9c Mon Sep 17 00:00:00 2001 From: SaraZoveydavian Date: Mon, 8 Jun 2026 13:33:56 +0330 Subject: [PATCH] comleting Report.md --- Report.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Report.md diff --git a/Report.md b/Report.md new file mode 100644 index 0000000..68d6ec1 --- /dev/null +++ b/Report.md @@ -0,0 +1,40 @@ +## start() vs run() +**Q1** +**the output:** +Calling run() +Running in: main +Calling start() +Running in: Thread-2 + +**answer to why:** run() is executed by main thread although start() is executed by thread object that been created. + +**Q2** +the difference between these two, is that when a thread (which has been created as an object) calls run(), couldn't execute it. So the method will be executed by the thread that created t1. +But by calling start(), you wouldn't see this behavior and method will be executed by thread that been created as t2. + +## Deamon Threads +**Q1** +**the output:** +Main thread ends. +Daemon thread running... + +**answer to why:** Main thread executes faster than deamon thread and exits the program so it doesn't let deamon thread execute properly. + +**Q2** +the thread will execute properly and we'll see "Daemon thread running..." prints for 20 times after printing "Main thread ends.". + +**Q3** +for example one of use cases is Logging and Auditing Services. Daemon threads can be used to log background activities continuously. + +## A shorter way to create threads +**Q1** +**the output:** Thread is running using a ...! + +**Q2** +Java Lambda + +**Q3** +it is the easiest way to create a thread. All three ways do the same execution. But with different usages. + + +