This may sound obvious, but don't use Java garbage collection on a regular base in your application.
I was just recently debugging a problem where an embedded Linux running Java code on the Oracle VM gets incredibly unresponsive when being connected to the internet, especially via Ethernet. We had never seen this problem before when connecting via GPRS or running our application on JamVM.
One morning, I started the application and everything suddenly was snappy. I realized, that the ethernet connection was down due to some misconfiguration. I fixed that and typed ifup eth0
and bam suddenly, the application was unresponsive again.
Then we wrote some test Java apps that imitated that actual application by opening a socket and transmit and read some data. No problem. So it couldn't be Java or the Socket.
Then I made the application connect to the server but without actually transmitting any thing: Snappy, again.
Long story short: I traced the execution path down to some very old lines of code I had completely forgotten which were implemented on very memory limited Java ME devices. Because we only had a few tens of kilobytes of RAM, I ended up inserting a Runtime.getRuntime().gc()
after every packet that was sent to free up memory (out of complete despair).
So i tuned out because JamVM has implemented its own garbage collection, on that VM it wasn't that bad. And when using GPRS, the connection was so slow, that the time between to packets was significantly larger and GC didn't have such a great influence.
After removing the old code, the CPU usage decreased by 50% and everything was snappy, again, even with ethernet and Oracle's VM.