scala - why the main app doesn't exit when calling a timer.schedule -


In the following, it runs a calculation after a delay of 2 seconds, but when the app is running, it never goes out What is the code to block the app to exit?

  Object Test App {import scala.concurrent._ import java.util._ import java.util.concurrent. {TimeUnit} val timer = New Java Ooty Timer () Def Timeout Future [A] (V: A, Delay: Long, Unit: Time Usenet): Future [A] = {Printline ("Inner") Val P = Promise (A) () Printlen ("Internal" ) Timer. Scheduling (new java.ttill Timurtsk {DRF ()) (PSUITS (V)}}, unit miles (delay)) println ("inner") p. Future} PrintLen ("start") Val x1 = Timeout future [int] (1 + 1,2, time USnet SEOCNDS) printline ("end") printen ("ebt")}   < / Div> 

valid timer = new java.util.Timer () a timerdad (Which has been implemented as a standard Java thread and an infinite loop), which is running in the background and prevents its application from exiting.

You can run System.exit (0) at the end of your script to stop all background threads.

Besides this, have you considered using Java timer instead?

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -