JAVA - Raspberry-pi - 应用程序即启动然后立即停止的服务 [英] JAVA - Raspberry-pi - Application as a service who start then stop immediately

查看:57
本文介绍了JAVA - Raspberry-pi - 应用程序即启动然后立即停止的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 raspberry 启动时启动一个 Java 应用程序,但我不知道怎么做?!

I need to start a Java app on raspberry's startup, but i can't figure how?!

我制作了一个在后台启动应用程序的简单脚本

I've made a simple script that launch the app in background

我在重启时将它推送到 crontab 中...

I've pushed it in a crontab at reboot...

我在 main 的第一行和 addShutdownHook() 中播放声音.所以我每次都能听到,应用程序启动然后立即停止......

I play a sound on the first line of the main and in the addShutdownHook(). So i can hear that each time, the app start then stop immediately...

当然,当我在 CLI 中启动它时,我没有这个问题!:@

Of course i don't have this problem when I launch it in CLI! :@

推荐答案

问题已解决,

如果有人有相同的,我会发布我发现的内容;)

I post what i've found if some one have the same ;)

我的应用程序运行一个线程,等待键盘输入运行实时测试和关闭应用程序,当这个循环被q"中断时,

My app run a Thread, waiting for keyboards entries to run live tests and shutdown app when this loop is break with 'q',

while( scanner.hasNext() ){
  ...
}

JavaDoc 说此方法可能会在等待输入扫描时阻塞",...可能会阻塞...

"This method may block while waiting for input to scan" say the JavaDoc, ... may block...

在服务的情况下,或者当您将应用程序置于后台时,has next"不会阻止,因此我的应用程序认为q"已发送并关闭.

In a case of a service, or when you put the app in background, "has next" don't block, so my app thinks 'q' was send and shutdown.

我刚刚添加了一个启动参数来使用或不使用 app asService,这会禁用或不禁用此等待循环..!

I've just added a starting parameter to use app asService or not, which disable or not this waiting loop..!

这都是普通人!

这篇关于JAVA - Raspberry-pi - 应用程序即启动然后立即停止的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆