Return values from Java Threads

后端 未结 9 1394
耶瑟儿~
耶瑟儿~ 2020-12-13 07:12

I have a Java Thread like the following:

   public class MyThread extends Thread {
        MyService service;
        String id;
        public MyThread(Stri         


        
9条回答
  •  攒了一身酷
    2020-12-13 07:39

    You could make a class which extends Observable. Then your thread can call a method in the Observable class which would notify any classes that registered in that observer by calling Observable.notifyObservers(Object).

    The observing class would implement Observer, and register itself with the Observable. You would then implement an update(Observable, Object) method that gets called when Observerable.notifyObservers(Object) is called.

提交回复
热议问题