问题描述:

This is the method that is getting the error

public int getMaxTimeBetweenCustomers()

{

return Integer.parseInt(maxTimeBetweenCustomers);

}

and this is the run method where the above^ method is being called. If I try to initialize the variable outside the method it does not work, so I'm not sure what to do.

 private void doSomething() throws InterruptedException

{

maxCustomers = myController.getMaxCustomers();

int myCounter=0;

String message;

while(myCounter < maxCustomers)

{

Customer customer= this.generateCustomer();

myServiceQueue = myServiceQueueManager.determineShortestQueue();

myServiceQueue.insertCustomer(customer);

myTime = System.currentTimeMillis();

myController.controllSetImages();

myCounter++;

System.out.println("my counter " + myCounter);

try

{

Thread.sleep(this.generateTimeBetweenCustomers());

}

catch(InterruptedException e)

{

message = e.getMessage();

System.err.println(message);

}

}

}

The above method doSomething() is called in the run method

网友答案:

You state that the getMaxTimeBetweenCustomers() method is causing your program to throw a StackOverflowException, but this is impossible if this method only contains the line of code you've shown. Something else is going on.

Likely that something else is that you've recursion going on. I have to guess, but perhaps doSomething() is being called directly or indirectly from within one of the methods it contains, one of the methods listed below:

  • this.generateCustomer();
  • myController.getMaxCustomers();
  • myServiceQueueManager.determineShortestQueue();
  • myServiceQueue.insertCustomer(customer);
  • myController.controllSetImages();
相关阅读:
Top