You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by sebb <se...@gmail.com> on 2012/10/16 11:15:23 UTC
[DAEMON] Re: prunsrv crashes when exiting
On 16 October 2012 07:02, Majid Azimi <az...@yahoo.com> wrote:
> Hi guys,
Commons user list is shared, so the subject line must be prefixed with
the component name, as I have done in this reply.
> I have written a simple windows service. It only creates a thread and that thread logs a random UUID to a file every 1 second.
>
> public class WindowsService {
> private static MyRunnable r;
> private static Thread t;
>
> public static void main(String[] args) {
> r = new MyRunnable();
> t = new Thread(r);
> t.start();
> }
>
> public static void start(String[] args) {
> main(args);
> }
>
> public static void stop(String[] args) {
> r.setStopped(true);
> try {
> t.join();
> } catch (InterruptedException ex) { /* do nothing */ }
> }
> }
>
>
> public class MyRunnable implements Runnable {
> private boolean isStopped;
isStopped needs to be volatile.
> private FileHandler handler;
>
> public MyRunnable() {
> try {
> handler = new FileHandler("C:\\access.log", 100000, 5, true);
> } catch (IOException | SecurityException ex) { /* do nothing */}
>
> isStopped = false;
> }
>
> @Override
> public void run() {
> handler.publish(new LogRecord(Level.INFO, "starting service"));
>
> while (!isStopped) {
Not guaranteed to pick up changes to the isStopped variable.
> handler.publish(new LogRecord(Level.INFO, UUID.randomUUID().toString()));
> try {
> Thread.sleep(1000L);
> } catch (InterruptedException ex) {
> isStopped = true;
> }
> }
>
> handler.publish(new LogRecord(Level.INFO, "exiting service"));
> }
>
> public synchronized void setStopped(boolean isStopped) {
Synchronization is useless unless both the writer and reader
synchronise on the same lock.
Drop the sync. qualifier and use volatile.
> this.isStopped = isStopped;
> }
> }
>
> I add this service with this command:
>
>
> prunsrv.exe //IS//MyService --DisplayName "Log Service" --Jvm auto --StartM
> ode jvm --StopMode jvm --Classpath "My jar file path" --StartClass win
> dowsservice.WindowsService --StopClass windowsservice.WindowsService --StartMeth
> od start --StopMethod stop
>
>
> I can start and stop the service and I can see "starting service" and "exiting service" at the log file. But when I stop the service I got this error:
>
> Commons Daemon Service Runner has encountered a problem and needs to close. We are sorry for the inconvenience.
>
> in the Event Viewer i see this message:
>
> Faulting application prunsrv.exe, version 1.0.10.0, faulting module jvm.dll, version 23.3.0.1, fault address 0x0012baba.
>
> Why is this happening? What is wrong with this program?
One obvious fault (as above) but I'm not sure that can cause the crash.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [DAEMON] Re: prunsrv crashes when exiting
Posted by Mladen Turk <mt...@apache.org>.
On 10/16/2012 11:15 AM, sebb wrote:
> On 16 October 2012 07:02, Majid Azimi <az...@yahoo.com> wrote:
>> Hi guys,
>
> Commons user list is shared, so the subject line must be prefixed with
> the component name, as I have done in this reply.
>
>> I have written a simple windows service. It only creates a thread and that thread logs a random UUID to a file every 1 second.
>>
It would be great if you could create JIRA issue and attach a .jar file that causes a crash.
Regards
--
^TM
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org