Threads in Java

前端 未结 9 890
野趣味
野趣味 2020-11-30 01:11

I was today asked in an interview over the Thread concepts in Java? The Questions were...

  1. What is a thread?
  2. Why do we go for threading?
  3. A re
9条回答
  •  囚心锁ツ
    2020-11-30 02:01

    http://learningsolo.com/multithreading/

    Multithreading is the process of executing two or more threads concurrently in a single program. Single core processor can execute one thread at a time but OS uses the time slicing feature to share processor time. Thread is a light weight process. The thread exists in the process and requires less resources to create. It shares the process resources. When the java application starts, it creates the first user thread for main which in turn spawn’s multiple user threads and daemon thread. The thread scheduler schedules the thread execution. When the work of all the threads are done, the JVM terminates the application.

    Every java application has at least one thread – main thread. Although, there are so many other java threads running in background like memory management, system management, signal processing etc. But from application point of view – main is the first java thread and we can create multiple threads from it.

提交回复
热议问题