-1

I have the following method:

 public boolean isMatch(List<T> sources, String captured) {
      boolean isMatch = false;
      return isMatch;
 }

I need to start a new thread inside it like below:

Runnable r = new Runnable() {
        public void run() {
            VERIFY();
        }
    };
    Thread s = new Thread(r);
    s.start();

The thread is supposed to perform some operations. When it finishes, I need to assign the return boolean value to the isMatch variable. How do I do this?

Talendar
  • 1,841
  • 14
  • 23
Ikiugu
  • 667
  • 1
  • 8
  • 16

1 Answers1

1

Since you need a return value, you should use the interface Callable<T> instead of Runnable. Look at what the docs say:

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

Note that a Callable is submitted through an ExecutorService.

Talendar
  • 1,841
  • 14
  • 23