Whenever I look in AlwaysUp, one Java entry always says “Waiting”. But if I open the browser I can connect to the server just fine. Why does AlwaysUp think that it’s not running when it is?
I suspect that your Java application is being blocked by another instance of itself. And when that happens, AlwaysUp just keeps trying to restart it. Let’s dig into the details.
Why AlwaysUp can’t start your Java application and constantly says its “Waiting”
First, understand that AlwaysUp only shows the “Waiting” state when it’s waiting to restart your application. You must have configured a delay on the Restart tab, as pictured here:
But AlwaysUp only waits before restarting the application. So the question is, why is your application stopping?
Since you mentioned that your Java server uses TCP/IP sockets, we have a hunch that there is a conflict with a network port. The problematic sequence probably plays out like this:
Indeed, AlwaysUp’s activity report — available by choosing Report Activity > Today from the Application menu — will likely confirm the futile attempts to start your application every minute. You probably have hundreds of entries in the Windows event logs too!
Why your application works even though AlwaysUp failed to start it
Your browser tests succeed because there is another copy of your Java application running. It’s listening to the port and responding to your browser’s requests.
You can confirm this situation by:
Opening the Task Manager (or better yet, Microsoft’s amazing Process Explorer) and locating the java.exe process already running;
Using the netstat command to find out which application already has the port open.
For example, this command identifies the process listening on port 8008:netstat -ano -p tcp | find ":8008"
As you can see below, the culprit was the process with ID 3484 on our Windows 11 PC:
But why doesn’t AlwaysUp “discover” the existing Java server and manage it?
First, realize that the current instance of your Java application was not started by AlwaysUp. That is, it’s running independently of AlwaysUp.
Second, you’ve got to understand how AlwaysUp works.
AlwaysUp is designed to start an application and ensure that it’s always running. Most importantly, AlwaysUp does not “discover” or “latch on” to an application that is already running. AlwaysUp can only manage and babysit applications that it starts itself.
The fact that a process on your machine is responding to your browser means nothing to AlwaysUp because that process was not started by AlwaysUp.
How to fix the problem
The solution is straightforward.
Simply terminate the current instance of the Java application running on your machine. Doing so will free up the port and allow a new instance started by AlwaysUp to secure the port and start properly.
How to ensure that AlwaysUp always starts your Java app
As you have seen, AlwaysUp will fail to start your Java app if there is another copy already running. The solution is to stop the existing server before AlwaysUp launches its own instance.
But what if this happens again and you’re not around to kill the non-AlwaysUp process? That may leave your system in a vulnerable state, with your Java application unprotected from crashes and other interruptions.
Fortunately, there’s a two-step fix. You can:
Write a batch file that terminates any process already listening on the port
Have AlwaysUp run that batch file right before it starts your application
That way, your Java application always starts properly because there won’t be anything holding on to the port.
Download our batch file that terminates the application listening on a given port
We’ve gone ahead and created a batch file that stops the process listening on a given port.
Download the batch file and save to a folder on your computer.
Plug the “terminate process by port” batch file into AlwaysUp
To make AlwaysUp run the “terminate process by port” batch file before it fires up your “main” batch file:
Double-click your batch file entry in AlwaysUp to open its properties;
In the Edit/View Application window, switch to the Startup tab;
Check the Run the following program/batch file box;
Enter the full path to the “terminate process by port” batch file you downloaded. Be sure to surround the value with quotes if it contains a space;
After the path, enter the Java application’s listening port number. We’ve entered 8008 for our application;
Check the Also whenever the application is restarted box as well:
Finally, save your changes.
With the “terminate process by port” batch file involved, here is the new sequence when you start your Java entry in AlwaysUp:
You will be good to go!