I have a Service that makes requests via a RestClient. What is the Java best practice between: Opening and closing the connection every time I make a request Opening the connection at class initialization and closing it in a ShutdownHook Something I didn’t think of Answer What is the Java best practice between There are no “best practices”. Please read
Tag: shutdown-hook
Should EntityManagerFactory be closed at application shutdown?
I have a Java application that has a GUI made with Swing and that uses two databases interchangeably. One of the two databases is mongoDB and the other one is MySQL. Which database to use is chosen with a command line option. For the MySQL database I am also using Hibernate and JPA. The code I have looks like this:
Java detect when application is closing
I learned Java for about 1 year some years ago. Now I wanted to go back to it, but my skills got a bit rusty. So I’m using Eclipse with the WindowBuilder to make an easy Form Application to get started again. I wanted to get a popup window when I exit the application because in future projects I need
How to ensure a piece of code is run before exiting a java application
I’m using a licensed API which has a method to acquire/release a license object from a license server that has a finite number of licenses. At the beginning of my application, I call the method to acquire the license, but I want to make sure that this gets released even if my program terminates/crashes abruptly (exceptions, SIGTERM, etc). Is the
How netbeans stops a run?
I’m programming with Java in Linux using Netbeans 7 and as my program (sometimes) could not exit (not in this eon, maybe) I create a thread to handle shutdown But when I launch the code with netbeans (F6) and stop it through the “STOP” button the thread is not created; but if I run the program through the terminal and