I have scenario where I am scheduling task at fixed duration repetitively.Fixed delay is generated by calling start method of another class that implements runnable interface using Thread.sleep(long ms ) method.
But when I test this application in my local pc it is working.But when I run this application in ibm blade server(64 bit) having OS(Windows server 2008 R2) it do not work as desired. It do not come out of sleep method.
Kindly suggest the solution?
Thank You in Advance.
There is not much information in your question to see what the problem is. Thread.sleep should either return or throw an exception. Maybe something different is happening. For example, an exception has occurred, caught and forgotten, or you have a deadlock somewhere. Anyway, different versions of Java sometimes have subtle differences causing bugs. You will have to investigate the problem yourself.
Try debugging the application. When it hangs, press Pause and examine all threads to find the hanging one.
If you can't install a debugger on the server, add System.out.println in every reasonable place of the code; reading the output in the console, you will probably be able to track down the issue.
If you can't launch the application with console, create a text file and write the messages to it. Don't forget to flush it every time.
Related
I have a java .jar file that i launch on an AWS instance in detached mode. So when i exit the ssh session, it still runs.
The app does some network stuff, and is expected to run for days until it finishes it task.
I have made logs all over the app, made log in the end of main method. I also made a global try/catch and added logging to the catch section.
Still, after some days i enter into ssh and see that the app just stopped running. No exceptions, main method did not complete because the log in the end did not trigger. It seems that the process was just killed in the middle of working. Sometimes it works for 5 hours, sometimes for 3-4 days without stopping.
I have no idea what could be the cause of this. I expect the java process to run until it finished, or until it crashes. Am i missing something?
upd:
it is an aws t2.micro, i think, the free tier one. It runs ubuntu 18.04.3 LTS
You need to monitor the server and application. The first thing to look at is your instance cloudwatch statistics for any CPU or memory spikes. If you find one, you know what you need to fix if you want to run your application on micro instance. For further reading
Monitoring Your Instances Using CloudWatch
Alternatively, you can collect and dump the java process statistics regularly when you are running the application. This can give insight of how heap,stack and cpu usage. Check this SO post for further details :
How do I monitor the computer's CPU, memory, and disk usage in Java?
I've created a simple web application on the base of spring-boot. It gets request, do some block operations (like writing to the console numbers from 1 to 10_000) and returns simple response.
When I start to test it with JVisual VM I've noticed that threads work in a strange way.
In the beginning, with low load, they don't work at the same time, they work in turn:
If I try to high-load application than Tomcat creates new Threads (It's OK as I understand) and after time threads work at the same time:
I've used Netling app to test application. It just simple request on localhost, nothing special.
Could you please explain why it works in this way? Or provide some links with description.
Thanks in advance!
I've understood the root of the issue.
On the JVisualVM I saw, that all Threads was blocked by each other, but I didn't know why. Now it's clear - I've use system.out.println() as a block operation, but Threads can't use it at the same time, the console is locked.
I've change console output to file output (use thread name as a filename to prevent lock) and start the application again. Now it's work as expected.
Stupid mistake, but I hope it will be useful for someone :)
I have a browser game built on a java web server using jsp.
I added a new module that uses some http session object and keep data in it. However, after it runs 3-4 hours, it suddenly stops working and freezes. When I check the error log, I dont see any exception thrown.
The server has 50-60 online in a moment.
I monitored the server using visualVM and here is the result after 4 hours until it stops :
I set the max memory as 1024Mb. As you can see its problem is not about the memory.
The thing that I notice is when the server stops, the thread amount increased.
According to the screenshot, should I doubt the httpsession object ? Why does the server stop responding ??
It looks like a system limitation or a deadlock.
Your thread graph looks like problematic : the number of living thread is important and never decreases. A web application should be stateless. The living tread count should rises when the requests arrive but also drops when the requests are finished.
I have not the impression it is the case in your application.
MGorgon is right.
You should also check "Deadlock detection" in jconsole.
If you use a JDK 6+ version, you could use ThreadMXBean. It has a findDeadlockedThreads() methods and other interesting methods to address your need.
Anyway, if it is not a deadlock, to get more information about the cause of the problem, I advise you to look in the system log whatever you OS is. You would have maybe interesting things.
We have a Java App that connects via RMI to another Java app.
There are multiple instances of this app running at the same time, and after a few days an instance just stops processing... the CPU is in 0 and I have an extra thread listening to an specific port that helps to shutdown the App.
I can connect to the specific port but the app doesn't do anything.
We're using Log4j to keep a log and nothing is written, so there aren't any exceptions thrown.
We also use c3p0 for the DB connections.
Anyone have ideas?
Thanks,
I would suggest starting with a thread dump of the affected application.
You need to see what is going on on a thread by thread basis. It could be that you have a long running thread, or other process which is blocking other work from being done.
Since you are running linux, you can get your thread dump with the following command
kill -3 <pid>
If you need help reading the output, please post it in your original question.
If nothing is shown from the thread dump, other alternatives can be looked at.
Hum... I would suggest using JMetter to stress the Application and take note of anything weird that might be happening (such as Memory Leaks, Deadlocks and such). Also review the code for any Exceptions that might interrupt the program (or System.exit() calls). Finally, if other people have access to the computer, makes sense to check if the process wasn't killed manually somehow.
I've written a Java app that allows users to script mouse/keyboard input (JMacro, link not important, only for the curious). I personally use the application to automate character actions in an online game overnight while I sleep. Unfortunately, I keep coming back to the computer in the morning to find it unresponsive. Upon further testing, I'm finding that my application causes the computer to become unresponsive after about 10 minutes of user idle time (even if the application itself it simulating user activity). I can't seem to pin-point the issue, so I'm hoping somebody else might have a suggestion of where to look or what might be causing the issue.
The relevant symptoms and characteristics:
Unresponsiveness occurs after user is idle for 10 minutes
User can still move the mouse pointer around the screen
Everything but the mouse appears frozen... mouse clicks have no effect and no applications update their displays, including the Windows 7 desktop
I left the task manager up along the with the app overnight so I could see the last task manager image before the screen freezes... the Java app is at normal CPU/Memory usage and total CPU usage is only ~1%
After moving the mouse (in other words, the user comes back from being idle), the screen image starts updating again within 30 minutes (this is very hit and miss... sometimes 10 minutes, sometimes no results after two hours)
User can CTRL-ALT-DEL to get to Windows 7's CTRL-ALT-DEL screen (after a 30 second pause). User is still able to move mouse pointer, but clicking any of the button options causes the screen to appear to freeze again
On some very rare occasions, the system never freezes, and I come back to it in the morning with full responsiveness
The Java app automatically stops input scripting in the middle of the night, so Windows 7 detects "real" idleness and turns the monitors into Standby mode... which they successfully come out of upon manually moving the mouse in the morning when I wake up, even though the desktop display still appears frozen
Given the symptoms and characteristics of the issue, it's as if the Java app is causing the desktop display of the logged in user to stop updating, including any running applications.
Programming concepts and Java packages used:
Multi-threading
Standard out and err are rerouted to a javax.swing.JTextArea
The application uses a Swing GUI
awt.Robot (very heavily used)
awt.PointerInfo
awt.MouseInfo
System Specs:
Windows 7 Professional
Java 1.6.0 u17
In conclusion, I should stress that I'm not looking for any specific solutions, as I'm not asking a very specific question. I'm just wondering if anybody has run into a similar problem when using the Java libraries that I'm using. I would also gladly appreciate any suggestions for things to try to attempt to further pinpoint what is causing my problem.
Thanks!
Ross
PS, I'll post an update/answer if I manage to stumble across anything else while I continue to debug this.
Update: my app involved multi-threaded processes each initializing their own Robot objects and creating input events asynchronously. I refactored the app to only contain one Robot singleton object, but the different processes still asynchronously invoke input commands. As far as I can tell, this did not change the behavior of my app. My next step might be to created a synchronized wrapper around the Robot singleton to see if that helps, but given the symptoms, I don't know why it would.
I've had problems using the Robot class before. I forget exactly what I've done, but it has caused the computer to lock up and I've been forced to reboot.
I'm not familiar with the vagaries of Robot, but Uncaught exceptions in GUI applications can produce very odd results as the event dispatch thread dies and restarts. You might get some ideas from How uncaught exceptions are handled.
This can happen if u activated any screen saver or some thing like that, then this robot actions will stop working
i got this problem in the following way
i am having some GUI based applications and i written some test code based on Robot class.
but if i activated screen saver in my system this test cases stopped working...
please check any such scenarios are there in your case
for Ross, I am pretty sure that you have a policy problem which mean that you don't have permission and getting block by win7. To get this permission you must create a policy and that is a big of a story. Check what info you can get from sun website.
For the others if your program stops working after some period of time it might be that you are not handling all of the exception in your program right. Try to get the line when it stops: you can do it by just sending a line of text to the system console, and rewrite it to get the performance you want.
For the rest check your code and check it good very good to see that you are not getting into a dead lock which might stuck your pc if it has something with it.
Also check to see the CPU usage and see if your program is overloading it if it does your CPU temperature control will restart or turn off your PC automatically.
If i didn't hit the problem, let me know; if you solved the case please let me know what you did.
We have two machines with almost exactly same behavior with Java applications.
One is with Windows 7 64 bit, where Eclipse 64bit and Java 6 (64bit) is causing exactly same freeze.
Other is with Windows 7 32 bit and Java application utilizing a lot of CPU and disk activity causing freeze.
Both machines are notebooks from Toshiba with modern CPU's (Core 2 Duo).
Also both machines have NOD32 anti virus installed.
Standard apps (Office, Skype, Firefox,...)
We seem to tracked down problem to NOD32. When we disable NOD32 it seems that beahaviour does not occure anymore.
I want to point out that I don't think it's NOD32 itself, but some combination of Windows 7, Java JDK and NOD32.
I ran into a similar issue on Mac OS X 10.6.7 but it was not freezing entire system but the entire java process where my application was running in, and interesting at random basis. Workaround for this was call:
Toolkit.getDefaultToolkit();
Before create any Robot, in example:
public static void main(String[] args) {
Toolkit.getDefaultToolkit();
//Blah blah
}
Same call is made in init method at Robot class so seems where the problems are coming from, this is stupid and does not make a lot sense to me but works perfectly now :)