2021년 8월 1일 일요일

daemon thread


데몬(디먼) 이라는 말은 영어 악마와 동일한 용어이다. 하지만 약간 철자가 다르다. 악마의 의미는 demon / 일반적으로 유닉스/리눅스 계열에서는 daemon이라는 이라는게 존재하였다.

daemon이란 일종의 서버 프로그램을 의미하고 항상 상주하는 process를 의미한다. 그래서 linux의 init.d 라던가 process이름뒤에 d 가 붙은 파일은 데몬 프로세서로 인식하게 된다.

아래 위키로부터 자세한 정보 확인이 가능하다.

https://ko.wikipedia.org/wiki/%EB%8D%B0%EB%AA%AC_(%EC%BB%B4%ED%93%A8%ED%8C%85)

https://namu.wiki/w/%EB%8D%B0%EB%AA%AC

그런데 이러한 개념이 python에서 오면서 혼동되기 시작한다. python의 디먼 thread는 main thread 가 죽으면 같이 종료되는 thread이다.

https://docs.python.org/3/library/threading.html

Note

 

Daemon threads are abruptly stopped at shutdown. Their resources (such as open files, database transactions, etc.) may not be released properly. If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event.


이런 개념은 java에서도 찾아볼 수 있다. stackoverflow 참고

https://stackoverflow.com/questions/2213340/what-is-a-daemon-thread-in-java

Java has a special kind of thread called daemon thread.

  • Very low priority.
  • Only executes when no other thread of the same program is running.
  • JVM ends the program finishing these threads, when daemon threads are the only threads running in a program.

What are daemon threads used for?

Normally used as service providers for normal threads. Usually have an infinite loop that waits for the service request or performs the tasks of the thread. They can’t do important jobs. (Because we don't know when they are going to have CPU time and they can finish any time if there aren't any other threads running. )

A typical example of these kind of threads is the Java garbage collector.

There's more...

  • You only call the setDaemon() method before you call the start() method. Once the thread is running, you can’t modify its daemon status.
  • Use isDaemon() method to check if a thread is a daemon thread or a user thread.



댓글 없음:

댓글 쓰기