Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Windows Service in Java?Helpful Member! 

drdad5727 (Programmer) (OP)
17 May 11 15:15
Does anyone know if you can get Java code to run as a Windows Service?

How about as a Windows Control Panel plug-in?

Thanks!
Diancecht (Programmer)
18 May 11 3:40
Sure, you can use any executable as a Windows service.

Cheers,
Dian

Helpful Member!  victorv (Vendor)
23 May 11 14:33
hi,

it may be easy or less, depending what you need to do when the
service receive the request to stop.

If you don't need this part, exist little programs as srvany.exe
(http://support.microsoft.com/kb/137890) that can "trasform"
any executable in a service. In this case the executable will be
"JAVAW.EXE YourClassInAJar...", but I am not sure what happens
when the Service is stopped.

The right way, is to:

1) I built a normal Window Service, using Visual Studio or
   what you prefere.

2) Test its mechanism, intercepting the Start and Stop Request

Until this point, we did not pronunce the Java "word".

3) Insert in the Start action routine, the run of:
"JAVA.EXE - YourJavaProgram", and everything will run fine,
and you'll see your Service in Started State.

4) What happens when the Service gets a Stop Request ? uhmmm !
You have to find a "talk" mechanism between tha Java code
and the C++ module, the one that handles this Stop Request.
A simple way, may be to use a file as semaphore: the C++ routine,
rather than kill the child process, can create such file.

If you want to run this Java program as a Service,
probably it will have a loop with a pause. Then, before sleeping, it could test the presence of such file: if it founds the semaphore, deletes it and perform a "hara-kiri":
it closes correctely the open handles (DB,files,sockets,...), and call a Java System.exit().

[You can use other mechanisms as sockets or other to syncrho
the twin, but you have time to complicate your life: do it later!]

The service will detect the child end
(if you run from command line, you'll see the prompt again)
and you'll see on the Service Manager, that your service wil be in stop state.

Probably you'd prefere "code": begin with the architecture,
then the code will arrive, also from others.

ciao
vittorio

 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close