• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stay resident in memory

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would it be possible in java to create a small program that will stay resident on memory?
Im interesting in developing a small application that will work as a deamon in linux or as a service in windows...
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to conform with the JavaRanch Naming Policy.
You can change it here: Change your display name.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for your question. You betcha. What exactly is the daemon/service going to be doing? I use a little java windows service for friend's machines that I work on that reports their IP address back to a server so if need be I can make some adjustments via the net. Let us know what you want to do and we can maybe step you thru it.
 
Pinda Ros
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i do apologise for the previous nickname, i would like a small application that will stay resident in memory. I want to monitor all ports for connections and if a connection is established then to be written in a log file.
thank you
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hello, i do apologise for the previous nickname.


No need to apologise. I thank you for complying so promptly.


I want to monitor all ports for connections and if a connection is established then to be written in a log file.


That part will be tougher than having a java app stay resident. How do you plan to monitor all the ports? Remember no raw sockets in java.net.
 
Pinda Ros
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well i was thinking of using c++ for the sockets, however the rest of the application i want it to be in java so that the porting i will have to do will be minimal.
So can you please tell me how can i make a simple program that will stay resident in memory?
thank you for your replies.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the procedure to autostart a daemon is going to be platform dependent. First, you're probably better off creating an executable jar file for your daemon. Let's say you want to start it up in Windows NT, 2K or XP for all users. Your easiest approach is to hack the registry. Here's the sequence:
1. Select Start->Run
2. Enter regedit in the text box and press OK.
3. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.
4. Select Edit->New->String Value or Right Click in the right pane and select New->String Value.
5. Change the new value name to something meaningful like "MyJavaApp".
6. Select Edit->Modify or Right Click in the right pane and select Modify.
7. Enter the command to start your Java app in the text box. It should be something like "javaw -jar MyJavaApp.jar".
8. Click OK and exit regedit.
9. Reboot and the app should be running.
Also, you should use javaw instead of java. It's been too many years for me to be comfortable with giving you a similar procedure for Linux/Unix systems. But you should be able to find that out in the man pages.
[ April 14, 2003: Message edited by: Michael Morris ]
 
Pinda Ros
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And again thank you for your reply, however i was hoping to be able to do that programmatically. i mean, to write java myapp and after that my program to stay in memory without blicking the console anymore. I hope i made it more clear now.
thanks again.
i hope there is a way to do that too...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear with me Pinda, we seem to have a slight communication problem here. What I posted will cause your program to forevermore be resident in memory, assuming that it runs in an endless loop and doesn't experience an irrecoverable Throwable. Is that not what you are wanting to do? You can start your java app in a command shell or from a batch file (or shell script on Unix/Linux) with javaw and no shell window will ever appear on screen. You can also start it in the background on a Unix box with java -jar MyApp.jar & or in Windows with start java -jar MyApp.jar.
[ April 14, 2003: Message edited by: Michael Morris ]
 
Pinda Ros
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im aware of java myapp & under linux.
however i would prefer if there was a way to do the same thing without &. i mean if i could do it using programming to solve this problems so i would not have to use this kind of "tricks" for each OS.
I hope i made it clear now ...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would you like to start your daemon from another java app? You can do this:

That will start your daemon running. In this case though, it would be wise not to use stdout and stderr from the daemon unless you plan to provide a thread in the parent app to consume all of the output from the daemon. Otherwise, the buffers will fill and it may lock the parent app.
 
Pinda Ros
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
aha... thank you very much ... well this is very close to what i wanted to do.
I wanted from within the same application to run and stay resident but i guess i could change few details in what you told me it would work... hopefully
thanks again
 
reply
    Bookmark Topic Watch Topic
  • New Topic