Develop #1

Open
mahdi_Goudarzi wants to merge 2 commits from develop into main
4 changed files with 42 additions and 0 deletions
Showing only changes of commit 0429dbb844 - Show all commits
+42
View File
@@ -0,0 +1,42 @@
# Theoretical Questions
---
## Question 1
### 1. `start()` vs `run()`
![cover](picture/Q1.PNG)
When we use the run method, we are actually in the main thread where the run function is called and it is executed in the same main thread, meaning there is a total of 1 thread. But when we use the start method, we actually have 2 threads, where a separate thread is created and the instructions inside the run function are executed in the new thread.
---
## Question 2
### 2. Daemon Threads
![cover](picture/Q2.PNG)
1. Since we have the Daemon state in this thread, the program terminates the daemon thread after the main thread finishes, and the desired thread cannot perform its action 20 times.
2. if we remove `thread.setDaemon(true)` this thread 20 times print "Daemon thread running..." and then program finished.
3. In real life : for example when we turn off the car . the thread that play song from radio should be killed
---
## Question 3
### 3.A shorter way to create threads
![cover](picture/Q3.PNG)
This syntax call `Lambda Expression`
when we use Lambda expression we will write less code, and we don't need to create a new class
but when we use Traditional model, our code is cleaner than other model, but we should write more code
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B