1
 public Boolean fetchGit(final Map obj) {
        Boolean taskStatus = false;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    fetchGitThread(obj);


                } catch (Exception ex) {
                    Logger.getLogger(GitTask.class.getName()).log(Level.SEVERE, null, ex);

                }
            }
        }).start();
        return true;
    }

Like in this code what if I caught an exemption. I'm not able to return anything form void run and can't use taskStatus variable. Please advice me here.

Picks Prabhakar
  • 335
  • 1
  • 3
  • 13
  • 1
    Just use ExecutorService and convert your Runnable to [Callable](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html) – rkosegi Jul 14 '18 at 14:44

1 Answers1

0

There are 2 possible ways i could think of.

1.) Use AtomicBoolean instead of Boolean, then you can modify the value in your runmethod.

2.) Create a class that extends Thread and implement a boolean getStatus() which returns your status.

BUT

The real problem you have, is that you are starting a Thread, and want the response of this Thread in your fetchGit method. This makes no sense at all. You could probably add a Callback as 2nd parameter to get notified when the method is finished, and remove boolean return type.

Halko Karr-Sajtarevic
  • 2,248
  • 1
  • 16
  • 14
  • What if I just call a function in the thread and then in function use try and catch? – Picks Prabhakar Jul 14 '18 at 14:46
  • And can you please show me an example? "The real problem you have, is that you are starting a Thread, and want the response of this Thread in your fetchGit method. This makes no sense at all. You could probably add a Callback as 2nd parameter to get notified when the method is finished, and remove boolean return type." I'm new in java that's why. Thanks – Picks Prabhakar Jul 14 '18 at 14:48