应用程序在开发模式下运行时守护程序线程或正常线程的影响

时间:2015-08-05 09:25:50

标签: java multithreading akka quartz-scheduler playframework-2.3

在我的网站中使用守护程序线程或普通线程有什么影响 播放应用。我有一些Akka Scheduler和Quarts Scheduler。应用程序启动时正在启动这些。我的应用程序在开发模式下运行,每当我对源代码进行更改时,它重新启动/自动重新加载应用程序导致线程死锁。停止这些线程的最佳方法是什么。

  
      
  1. 在这里使用守护进程线程是否合适?
  2.   
  3. System.exit(0)在这里会有用吗?
  4.   
  5. 是否有其他方法可以停止在调度中特定时间内正在休眠的这些正在运行/等待的线程?
  6.   

我正在尝试做类似的事情:

@Override
public void onStart(Application app) {
Akka.system().scheduler().schedule(Duration.create(2000, TimeUnit.MILLISECONDS), Duration.create(60000, TimeUnit.MILLISECONDS),
  () -> {
  String url = Play.application().configuration().getString("localloadbalancer.ip");
  url = url + "initCallOut";
  Logger.info("Calling initcall from global.java::" + url);
  HttpClient client = HttpClientBuilder.create().build();
  HttpGet request = new HttpGet(url);
  try {
  HttpResponse response = client.execute(request);
  int statusCode = response.getStatusLine().getStatusCode();
  Logger.info("Status Code::" + statusCode);
  if (statusCode == 200) {
   //Do stuff here
  } else {
   //retry
  }
  } catch (IOException ex) {
  Logger.error("Error in Initcall::" + ex.getMessage());
  }
  }, Akka.system().dispatcher());

  // Quartz scheduler starting here

  try {
   QuartzScheduler.startScheduler();
  }
  catch (Exception ex){
   System.out.println("Scheduler Exception::"+ex.getMessage());
  }
  }

0 个答案:

没有答案