I am an experienced java developer.Of now I have started learning multithreading in java.I am able to grasp most of the concepts but still I am unable to visualize applications running on threads.I know the concept but somewhere if I am given a problem statement, I am unable to think or visualize it in threads.How should my approach be in order to start visualizing applications in threading and start coding the applications in threads?

  • 1
    recommended reading: Where to start – gnat Aug 29 '14 at 7:01
  • I think I understand your question. The first step is stop using vector, and use something like List instead. The next step is perhaps initializing with enough cache from info boxes, so that when a web container like Tomcat or GlassFish starts, things can run ok. Perhaps one should also think about less use of modularized Unit. Multi threading is a better way to make sure things go well. – InformedA Aug 29 '14 at 7:04

The easiest way is to think of threads as processes (and this is the case in some unixy systems that spawn a new process where some systems would create a new thread).

A process is a blob of code and data with a stack and a single thread anyway.

Once there, you can start to imagine sharing data between threads- its easier in a single process with multiple threads, but dangerous. Thinking of each thread as a "process" will help visualise the importance of understanding where shared data is managed.


I usually think about thread as an arrow that execute your code(Like when you're debugging on Eclipse or Netbeans);
This little arrow executes your code, but instead of having just one, you'll spawn another one.

In Java, you have to let a class implements the Runnable interface that lets you implement the run() method;
When you want to spawn a new thread that runs in parallel than the first one you have to open an object Thread, passing the object that implements Runnable and start it.

public class SaimLol implements Runnable {
    public void run() {
        while(true) { 

public class Main {
    public static void main(String... args) {
        SaimLol myObject = new SaimLol();
        Thread threadSaim = new Thread(myObject);


What is the thread programming goal?
When you start the thread calling the threadSaim.start() a new "arrow" spawns and the code will be executed calling concurrently the methods doSomethingInSaimLol() and doSomethingInMain();
With threads you can do things like control two parts of your code concurrently, or more advanced things like build a semaphore to let know the first thread if all variables are setted and it can goes.


I think the best way to deal with parallel programming is to keep in mind the global data you're dealing with and not so much the code you're writing on. As soon as you stumble upon global data (such as a member variable), you have to think to yourself: Is it possible that this variable get's accessed by multiple threads?

The advantage of this approach is that you're thinking about what's essential to multithreading, which is accessing global data, and not your code. It doesn't matter what code is accessing it; it could be the code you're currently typing, or a code somewhere else. I don't think about whether my code will be executed in parallel, I'm just caring about the variable I'm acessing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.