scheduled_02.bmx 727 B

1234567891011121314151617181920212223242526272829303132333435
  1. '
  2. ' Demostrates use of a scheduled thread pool with recurring tasks.
  3. '
  4. SuperStrict
  5. Framework BRL.Standardio
  6. Import BRL.ThreadPool
  7. Local pool:TScheduledThreadPoolExecutor = TScheduledThreadPoolExecutor.newFixedThreadPool(11)
  8. pool.schedule(New TTask("One-shot Task"), 5, ETimeUnit.Seconds) ' after 5 seconds
  9. pool.schedule(New TTask("Recurring Task"), 3, 5, ETimeUnit.Seconds) ' after 3 seconds and then every 5 seconds
  10. Delay(10 * 1000) ' wait for 10 seconds and then shutdown the pool
  11. Print "Shutting down the pool..."
  12. pool.shutdown()
  13. Print "Done"
  14. Type TTask Extends TRunnable
  15. Field message:String
  16. Method New(message:String)
  17. Self.message = message
  18. End Method
  19. Method run()
  20. Print message
  21. End Method
  22. End Type