1

One of my application tasks is to get the current system date and compares it with a stored date in my database,i want to make a thread that runs once the system starts in order to get the current date, in other words i want my application to work in the background once the system is started, how to do that,thanks.

4

2 に答える 2

1

Apache Procrunを見てください。Java プログラムを Windows サービスとしてインストール/アンインストールできる Windows 実行可能ファイルです。

サービスのインストールは次のようになります (プロジェクト サイトから)。

prunsrv //IS//TestService --DisplayName="Test Service" \
    --Classpath=myAwesomeService.jar \
    --Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm \
    --StartClass=my.awesome.package.MyStartClass --StartParams=arg1;arg2;arg3 \
    --StopClass=my.awesome.package.MyStopClass --StopParams=arg1#arg2

その後、次を使用してサービスを開始/停止します。

net start TestService
net stop TestService

またはマイ コンピュータのサービス ビューを使用します。

開始/停止クラスmain(String[] args)には、スレッドの開始/停止を処理するメソッドが実装されている必要があります。

于 2012-06-21T11:20:07.143 に答える
0

Windows サービスを作成し、Windows サービス内でスレッドを実行し、サービスのスタートアップを自動に設定すると、ジョブが実行されます。

于 2012-06-21T11:16:05.197 に答える