0

I read this question and some documentation, and I would want to know if these two codes are equivalent:

in Java SE8:

 Thread th1 = new Thread(() -> { doStuff(); });    
 th1.setDaemon(true);
 th1.start();

In C#:

 Thread th1 = new Thread(doStuff);
 th1.IsBackground = true;
 th1.Start();

I've read the MSDN documentation, but I wanted to know it they are equivalent from the framework point of view (garbage collection, finalizers, memory management, etc). In both cases: th1 dies in the same way after its parent thread "dies"?

MSDN mentions "a process", but Oracle mentions "the JVM itself". This is what confuses me.

Community
  • 1
  • 1
Broken_Window
  • 2,037
  • 3
  • 21
  • 47
  • http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground(v=vs.110).aspx – kosa Dec 03 '14 at 22:02
  • @Nambari: Yes, I've read a lot of that, I think I'll need to edit my question – Broken_Window Dec 03 '14 at 22:04
  • 1
    JVM itself is a process. Every programming language uses its own terminology and its own architecture, don't compare word to word. – kosa Dec 03 '14 at 22:09
  • "...after its parent thread "dies"?..." I don't know about .NET, but in Java, there is no parent/child relationship between threads. If thread P created thread C, that may mean something to your application, but it means nothing to the JVM. – Solomon Slow Dec 03 '14 at 22:31
  • @james large: oops, as Nambari said: it is all in the jargon. In .Net, it is common to say Thread P would be the "Parent" and Thread C would be "the child". I found this interesting info http://stackoverflow.com/questions/11722749/how-to-find-the-name-of-the-parent-thread – Broken_Window Dec 03 '14 at 22:44

1 Answers1

0

Yes, they are equivalent. From the docs

A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724