After my application finishes I want to close the spring context. The relevant code has an ApplicationContext reference but I couldn’t find a close method. Answer Downcast your ApplicationContext to ConfigurableApplicationContext which defines close() method:
Tag: java
How to remove a task from ScheduledExecutorService?
I have a ScheduledExecutorService that times a few different task periodically with scheduleAtFixedRate(Runnable, INIT_DELAY, ACTION_DELAY, TimeUnit.SECONDS); I also have a different Runnable that I’m using with this scheduler. the problem starts when I want to remove one of the tasks from the scheduler…
Printing stack trace in JOptionPane
My question: How can i put the text e.printStackTrace prints into a JOptionPane window My code is currently as follows: excuse the poor formatting 😛 this both prints the stack trace in the command line interface(i am using terminal) and it creates a JOptionPane but NOT with the same info as e.printStackTrace(…
Initializing C3P0 connection pool takes 2 min
I can’t wrap my head around why the initialization of a c3p0 connection pool takes 2 min in my Hibernate application. This is in my Hibernate.cfg.xml: The connection settings are set in my HibernateUtil file when building the session factory. The pool is initialize when the first transaction in my tests…
How to create my own file extension like .odt or .doc? [closed]
It’s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago. The community revie…
How to use google-oauth-java-client?
I want to use google-oauth-java-client to get authorization code from Sina Weibo. This is the GET method that get code from Sina https://api.weibo.com/oauth2/authorize?client_id=70090552&…
Why SimpleDateFormat.format() and SimpleDateFormat.parse() are giving different time though setting only one TimeZone?
I am trying to set the Timezone to the different country’s timezone with help of SimpleDateFormat. SimpleDateFormat.format() returns correct current time of the given Timezone, but SimpleDateFormat.parse() returns local current time, I don’t know why this is happening. Here is the my code: The out…
How do I check if a string contains a list of characters?
How do I check if a list of characters are in a String, for example “ABCDEFGH” how do I check if any one of those is in a string. Answer use regular expression in java to check using str.matches(regex_here) regex in java for example:
In Java servlet, cookie.getMaxAge() always returns -1
If I set a cookie with a setMaxAge() well into the future, when I read the cookie back into memory in a subsequent request, the getMaxAge() gives me back a -1. I have checked the actual cookie via Chrome’s settings, and inspector, and I can verify that the expiration date is indeed set 60 days in the fu…
How to add servlet Filter with embedded jetty
I am embedding jetty into my app, and trying to work out how to add servlet filters (for cookie handling). The wiki and the javadoc’s dont make it very clear, what am I missing: The only info I have found on this is a forum post suggesting the documentation on this needs to be improved. Answer Update: F…