Solved

Java program shceduled through cron job going in the sleep mode

Posted on 2011-03-17
16
732 Views
Last Modified: 2012-05-11
Hi,
I have scheduled a Java program to run through cron tab. The java program calls itself recursively and is supposed to run for about 7 hours. However, after a few runs it's going into sleep mode (SI process status in UNIX).

The same program runs absolutely fine if run through the console.

Please let me know how to resolve this issue.

Thanks.
0
Comment
Question by:orazen12
  • 8
  • 3
  • 3
  • +1
16 Comments
 

Author Comment

by:orazen12
ID: 35154190
Let me also add here that it goes into the sleep mode and occupies 100% memory if run through crontab. However it occupies less memory if run from the console. Just in case this helps.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35154300
What do you mean by Java program "calling itself recursively" ?
0
 

Author Comment

by:orazen12
ID: 35154368
Actually it's like an infinite loop with every run checking for the current time. And if the time condition is satisfied it breaks. The issue is that it runs fine if run from the console. But with crontab it is giving problems and goes into sleep mode.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35154391
But that is not called recursivley - you simply have a loop inside the program and on each cycle you check the time and normally go to the next cycle
 unless it is too late. But you do not invoke the same program  from inside this program itself?
0
 

Author Comment

by:orazen12
ID: 35154469
Yes you are right. But as I said, it runs fine from the console but not with crontab.

If you were concerned about multi threading, yes they are being used in the program.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35154610
I was mostly concerned by the term "recursively" which you used. I guess recursion in some cases may lead to memory issues. But, as I understand you don't have recursion. Did you try to increase memory required for java, say by using -Xmx500M on the startup line.
0
 

Author Comment

by:orazen12
ID: 35154620
Ok.
Do you think increasing the memory would help as the same program is running absolutely fine  from the command line and is using less memory.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35154769
Make sure that the program follows the singleton pattern or you might get multiple instances of the app running when cron fires.

From what you say about the app, it looks like it's designed to only be run once, not regularly by cron
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35155405
add some logging to get a better idea whats happening.
Remember cron jobs will run in a different environment than when run from the command line, and you can also control that environment once you find out the cause of the problem which hopefully the loggin should uncover
0
 

Author Comment

by:orazen12
ID: 35162909
It is working today. It's very strange. Yesterday the comments were also not getting printed but today it's working fine. I'll wait for 2-3 days (Monday-Thursday) more to observe whether it works fine or not.

Thanks.
0
 

Author Comment

by:orazen12
ID: 35309397
It is acting very strange. The first time it runs through crontab it goes into the sleep mode. Then if we reschedule it manually through crontab it works.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35309432
I'm confused as to what is happening here. If your program runs ok from the command line then why are you calling it with cron?  cron is designed to run things repeatedly, which is happening already by the sounds of things when you run it at the command line. If you want to start it at a certain time, then you probably need the 'at' program, not cron

man at
0
 

Author Comment

by:orazen12
ID: 35309581
CEHJ
Thanks for the suggestion. 'at' could be a good solution. The reason I'm using crontab is because I have to run the program everyday Monday-Friday. Would 'at' have a particular advantage over crontab in this scenario?

Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35309590
No, if you run it regularly, you should be using cron.

How is the termination of the app determined?
0
 
LVL 92

Expert Comment

by:objects
ID: 35310809
> Would 'at' have a particular advantage over crontab in this scenario?

at is not suitable for that, check the environment as I suggested above. and do a thread dump to see exactly where it is hung

0
 

Author Closing Comment

by:orazen12
ID: 35348538
Ok. Finally got it working. Basically two programs were scheduled through crontab to run every minute. Program A was updating a file and Program B was reading that file. It seems that while program A was updating the file it must be putting some lock on it because of which program B was going in the sleep mode. I've put a delay of about 10 seconds in the script for Program B so that it starts reading the file only when Program A has finished updating the file.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 119
Error with Java/Cache JDBC Classpath 2 30
thymeleaf natural templating vs JSP 2 66
maven project error 5 48
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now