Related to JMS Listener - java

Currently I am facing issues with related to JMS Listener. JMS listener is not actively picking all the messages, instead randomly selects the input messages and process it. Because of this, for few messages I could see user details being displayed, for others its not. There is inconsistency in displaying results. It is difficult to trace where the listener is actively running in the background because in my colleague's local machine, I could see listener picking messages randomly and processing it.(he does not have my code changes and so user details are not displayed). Have anyone faced this scenario? Is there any solution? I tried to push the same message (which does not show user details) from my local workspace and it is executed fine. This is to ensure my code is right or not.

Related

View the console output of a running Java program, from another Java app

I have a program made in Java, which you want to configure as an operating system service. The program reads data received by socket, which processes and stores it. It also logs errors and finally prints the information flow all the time in console to observe its operation.
After setting it up as a service, a need arose.
How do I view the print activity in console, if the application is in the background and therefore the console is not open?
Is there a way to view the console output of that application?
It occurred to me, if it is possible to create another Java application to read and print the console output of the created service. Would that solve the problem?
Thank you very much for your comments, after researching a little more thoroughly, according to your suggestions, i developed an IPC communication system via Sockets, in which, an swing application connects to the service and requests Every 2 seconds the required information and the sample in the app

Java Web/JSP program with code running in background 24/7

What is the best way to implement a notification system that keeps running in the background?
This system will generate these notifications when certain conditions are met. The server has to monitor the database constantly for these events and update a notification log when they occur. When a notification is generated, an SMS is sent to designated people.
With a traditional JSP system, the code only runs when a user visits the site. How do you program the server to have the code running 24/7? Also, how do you feed back these events asynchronously to the front end so the front end does not need to keep polling the database?
The question is very vague, but i'd say you need a task scheduler, some application servers like wildfly already have a task scheduler, or you can use something like quartz, and set it to run every as many times as you need.

How to make a webpage reload automatically when another session of the same website has done some work parallely?

I'm working with a project of patient queuing using JSP and Eclipse IDE. In it, I require a message to be conveyed between two different sessions of same website (i.e. the doctor's and compounder's homepage are alive).
As soon as the doctor finishes consulting a patient, a message is to be passed to the compounder's home page saying "To send new patient in".
I checked session creations and MVVM. But it doesn't satisfy me. Will anyone please help me out on this? I have tried an "auto refresh" inside JavaScript, but I ended up in an infinite loop.
This is a very broad topic. You can go about it in several ways and using several technologies (message queues/brokers, websocket, dwr, etc).
This is similar to building a chat application so maybe search for that online (again another broad topic).
If you want something very simple (and most of the times inefficient - but that depends on your requirements) you can go about it this way:
Have a simple database behind your application (an application wide thread-safe queue should work too but a database gives you persistance in case something happens to the application, like a server crash);
once the doctor finishes the consultation, his page saves an entry to the database, a flag basically;
The compounder's page has an Ajax request that from time to time (say 10 sec) looks for the flag in the database;
if the flag is found it displays a message on the compounder's page to send the next patient and then resets the flag
repeat step 2.
Those are broad steps to build something simple. As I said, not the most efficient way. Search for how to build a chat and you'll find better ways since a requirement for chat applications is to be fast and scalable.

Vaadin and Liferay IPC Out of Sync error

I'm using 2 Vaadin Portlets on the same page in Liferay. The first one shows a Table of entries and each row has a button to show details about this entry.
When the button is clicked an IPC event is send which is received by the second portlet, which then switches also to a table view showing the content.
By clicking a close button on the first portlet, the second one will receive again an IPC Event and go back to its original state, which is a blank view that has only the Liferay IPC listener attached to it.
My problem is that after the third click I get an out-of-sync error by Liferay. When the view is changed I always attach it to the main window. So I don't create additional windows that have the same name.
When I use only one portlet on the page I can switch back and forth without any problem. Could it be that the at some point the browser want to fire an event on the client side, but the IPC is already gone on the server side ?
Its really hard to determine the root of this problem.
You are on the right track. IPC works on client side and out-of-sync is caused by non existing component being called from the client to the server.
There might be a few thins causing this, but some scenarios to check:
You say you have a close button that clears the display. Calling Application.close() maybe? This actually might cause a new (server-side) application instance to created and called instead of the original.
You might be creating a new instance of the IPC component, but the old one is still registered and tries to send something (to its non-existing server part).
JavaScript timing issues could cause the IPC events to be sent in different order that you might expect. I see this unlikely if it the behavior is always consistent, but still a possibility.
Hope this helps you to narrow down the case a bit and find a solution. Keep this question updated.

Access by one client at a time

My requirements are as follows.
I have a web application developed in java.
I have a link in the html page. When the first client clicks submit button in the html page the batch file should run.
Meanwhile when the other client clicks the submit button he should get message that the page is busy.
If the first client clicks release button then the other clients must be able to run the batch file.
How can I do that?
Set a flag when the submit button is clicked and clear it when the release button is clicked.
Depending on your architecture, the flag can be anything from a boolean variable in your code, a special entry somewhere in your database to a temporary file.
When the submit button is clicked, check whether the flag is already set. When it is, return an error message stating that the page is busy.
In pseudo code:
if (flagIsSet()) {
showPageIsBusy();
} else {
setFlag();
startBatchFile();
}
Remember to clear the flag when the batch file finishes or the release button is clicked and somewhere in a finally block.
You also have to make sure that only the client who started the batch file can release it and clear the flag.
As pointed out by Avi in the comments, you should also remember to synchronize access to the flag.
Pseudo algorithm:
Modify the batch file to run a servlet before and after batch operations.
Before running batch file, set a servlet or flag that will register a file or database or a session variable that I am being executed and at completion of batch file, set a servlet or flag that will register a file or database or a session variable that I am being released
When user clicks release button, run the same servlet which will relase the flag.
When User submits submit button, check for that flag whether it is executed or released, depending upon you alert your client.
you could use a field in servlet class (a big nono otherwise) for a flag.
If your application happens to run on multiple load-balanced servers, then you face the same problem I do :) I submitted a question earlier about it, but unfortunately I didn't get any response. In any case, you can see my solution for the problem as an answer to my question here.
That is a Singleton or better an Application-Bean. This Bean should kick of your long running background task and provide information about it, e.g. if it is running and maybe stuff like when did it start, who started it and if you could the progress, so you could display a progress bar as well.
If you would tell us, what web application framework you use, we could give better tips, I think.

Categories

Resources