Press "Enter" to skip to content

Coding Q & A

What is the difference between a Thread and a Process?

A process has a self-contained execution environment, where it generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space. On the other hand, threads (which are sometimes called lightweight processes), provide a different execution environment, where they require less resources to be created and and most importantly, share the process’s resources, including memory and open files.

What are pros and cons of multi-threaded applications?

In Multi-Threaded applications, multiple lines of execution are running concurrently. That in itself can improve performance since when one thread is waiting for a resource (say Input from the keyboard), another can run in the CPU, making the application as a whole more efficient. Furthermore, in today’s dual or even quad-core CPUs the threads can even “physically” run in parallel. Multiple threads share the heap memory, hence they require less resources to be created and can interact easily with each other than processes.

What is the difference between run() and Thread.start() methods?

Both are viable. However, run() will just call the method in the current thread. Just like running your own myCoolFooMethod(). It will not start a separate thread. On the other hand, Thread.start() will start the run() method on a separate thread from the current one.

How can I create 1 or more threads in Java?

There are a 2 ways you can create a thread in Java, implement a Runnable or extend the Thread class. For more details, advantages and disadvantages on both check How to implement threads in Java

What are Green Threads in Java?

In computer programming in general, green threads are scheduled and implemented by a virtual machine, compared to the native operating system thread that are scheduled by the OS. This means they are implemented in user space, compared to the native OS threads that are implemented in kernel space. They are a great way to support multi-threading in an OS that does not have native threading support.

Note: This page will be updated continuously. Check back in 24 hrs for more content 🙂

The following two tabs change content below.
If you like one of my posts the best way to support is give it a thumbs up, comment, or share it on social media 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *