0

I need a return value from a server class that looks basicly like this.

I need to return that object while the server keeps running. What is the easiest way to accomplish that?

Object o = null;

try {
  ServerSocket socketConnection = new ServerSocket(123456);
  while(true)
  {
   Socket pipe = socketConnection.accept();

   ObjectInputStream serverInputStream = new
          ObjectInputStream(pipe.getInputStream());


   object = (Object)serverInputStream.readObject();
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
claire
  • 1
  • 1
    return where? Do you want your method to be `asynchronous`? – Codebender Jul 24 '15 at 12:07
  • yes. The (it's actutally kinda homework) task it to build a holiday planner. Holiday requests can be send from different clients (Swing, GWT) to the server. At this point it is used by a class using service methods to prompt the database. I thought that might be done with some Callback method ? – claire Jul 24 '15 at 22:24

1 Answers1

0

There is no way that a method return some value and still continue execution. But you can fork a thread and then return the value (When you start a thread it will immediately return the control to the same program). Note that the order of the threads will not be a guarantee.