Saturday, October 30, 2010


I’ve been setting up a Quartz scheduler recently. We wanted it to store the jobs in a Database. Quartz helpfully comes with a set of sql scripts for virtually all DB’s to create and manage all jobs, triggers, schedules etc via a transaction and cluster aware scheduler, so there is no need to think about that aspect of it. The scripts are all stored in the Quartz distribution under docs/dbTables folder.

Once the tables are all set up you can use the example application provided with Quartz to test out the DB persistence (Example 13). Configure it to point to your database by updating the file

We then wanted to Spring-ify it. This was straightforward


public class RunSchedule {

static Logger _log = LoggerFactory.getLogger(RunSchedule.class);

public static void main(String[] args) throws Exception {

BeanFactory springContext = new ClassPathXmlApplicationContext("Spring-Quartz.xml");



public static void cleanUp(Scheduler inScheduler) throws Exception {

_log.warn("***** Deleting existing jobs/triggers *****");

// unschedule jobs

String[] groups = inScheduler.getTriggerGroupNames();

for (int i = 0; i <>

String[] names = inScheduler.getTriggerNames(groups[i]);

for (int j = 0; j <>

inScheduler.unscheduleJob(names[j], groups[i]);



// delete jobs

groups = inScheduler.getJobGroupNames();

for (int i = 0; i <>

String[] names = inScheduler.getJobNames(groups[i]);

for (int j = 0; j <>

inScheduler.deleteJob(names[j], groups[i]);






<beans xmlns="" xmlns:xsi="" xmlns:p=""xmlns:jee=""

xmlns:tx="" xmlns:context="" xmlns:jms=""xmlns:util=""


<bean id="runMeTask" class="ie.bge.middleware.RunMeTask" />

<bean name="runMeJob"


<property name="jobClass" value="ie.bge.middleware.RunMeJob" />

<property name="jobDataAsMap">


<entry key="runMeTask" value-ref="runMeTask" />




<bean id="simpleTrigger"


<property name="jobDetail" ref="runMeJob" />

<property name="repeatInterval" value="5000" />

<property name="startDelay" value="1000" />


<bean id="cronTrigger"


<property name="jobDetail" ref="runMeJob" />

<property name="cronExpression" value="0/5 * * * * ?" />


<bean name="plannedDowntimeScheduler"

class="org.springframework.scheduling.quartz.SchedulerFactoryBean" init-method=”start”>

<property name="quartzProperties">

<util:properties location="/" />


<property name="applicationContextSchedulerContextKey"

value="applicationContext" />

<property name="waitForJobsToCompleteOnShutdown" value="true" />



All works as expected.

N.B. Note the init-method attribute for SchedulerFactoryBean. This is to automate the starting of the scheduler after it is instantiated. It is better than having a code based startup, (which would implement the Spring InitializingBean)

When we integrated it into our main application however we started having issues.


Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: ORA-00942: table or view does not exist

[See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist


The problem was due to autowiring. We had a datasource defined for a different purpose that was getting autowired into our SchedulerFactoryBean. (We were defining the datasource via the, and not injecting the datasource).

Manually wiring the correct dataSource fixed the problem. (or turninng off autowiring should also work as suggested by jrsisson)


BeanFactory or ApplicationContext?

Taken from Spring website

Users are sometimes unsure whether a BeanFactory or an ApplicationContext is best suited for use in a particular situation. A BeanFactory pretty much just instantiates and configures beans. AnApplicationContext also does that, and it provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP.

In short, favor the use of an ApplicationContext.

(For the specific details behind this recommendation, see this section.)

CSS Javascript quickie

Center (Centre) a div

Its easy, but its not necessarily obvious. To centre a div you need to set the width, and the margin-left and right to auto,



width: 500px; margin-left: auto ; margin-right: auto ;


To center text within a div use.

text-align: center ;


Useful links explaining with nice and simple explanations of objects in javascript (I wonder how I never “got it” before considering how simply its described here)

Also the prototype modifier. Basically it allows properties, and methods to be added to objects. Effectively making javascript OO, instead of purely functional.

Saturday, October 16, 2010

Recording a desktop demo video/ viewlet

Just a quick note about recording a desktop demo (viewlet). These are very handy for demo’s on using software etc. They allow you to record the screen activity, while adding voice over commentary, and popup overlays.

One of the best freeware recorders is Wink

Also some image compression stuff on here.

Svn identity/ login

If subversion in eclipse is pestering you for login credentials every few seconds, then your credentials may have got corrupted.

You can reset the stored credentials by deleting the auth directory.

This is usually located at

Unix (linux/ Osx)


USER_HOME/Application Data/Subversion/auth

Taken from

.keyring file only used when JavaSVN adapter is selected.

Also, your repository may allow anonymous read access, so browsing and
update operation doesn't require you to log in. Supclipse only prompts for
credentials when credentials are requested by Subversion server.

Weblogic JMS

Link for looking up all jms queues using jmx

You can use a JMX program, WLST, JConsole, or the console.

See the documentation on using WLST

See the documentation on writing JMX clients

See the MBean reference documentation

The JMX distributed queue mbeans have type = weblogic.j2ee.descriptor.wl.DistributedQueueBean

You can either walk down the hierarchy starting at the Domain MBean and into the JMSSystemResource MBean or you can query for specific MBean types.


One issue that I’ve seen on a client site.

An OSB proxy is set up to consume from a JMS queue. Data is injected into the queue but the Proxy does not consume it.

(Only seen when custom dispatch policies were used)

This is a weblogic bug. The workaround is to go through the configuration of the proxy, and assign it a different Dispatch Policy. This would enable consuming of the queue. Then you can simply rollback the change in OSB, and consuming will continue.

JMS Unit of Order

Message Unit-of-Order is a WebLogic Server value-added feature that enables a stand-alone message producer, or a group of producers acting as one, to group messages into a single unit with respect to the processing order.
Note that it appears to cause problems with the JMS Api's for viewing message payloads.

Editied Note.. We found an MBean API for discovering these. It involves using the MBean operation getMessages (specifying a flag). I will blog about it later

Weblogic Roles

Just a quick reminder for myself. This is easy but on initial inspection it seems like there is something missing. In fact it is easy, but appearance can be confusing.

The high level is. You are using weblogic server to host your apps. You want some security policies for your apps. It therefore makes sence to use the weblogic security realm, and its roles, groups, users and policies to manage the entity.

-. Create new Role(s).

From weblogic console, goto Security Realm, Select realm, select Roles and Policies.

Now expand the global Roles, and click on the Roles link. This will allow you to create custom roles.

-. Create/ edit Groups to include new Roles

Assign users to groups

JSTL snippets

Simple when you know how. Frustrating and time consuming when you don’t
If/ else
Because of the xml format we can’t have a
<c:if test=”${actionBean.test}”>
Instead we have to use choose, when and otherwise.
<c:when test="${actionBean.test}”>

Looping through lists
Realated to above, I was trying to test if a list was populated.
First attempt was
<c:when test="${actionBean.result.size>0}">
javax.el.PropertyNotFoundException: The class 'java.util.Collections$Synchronize
dCollection' does not have the property 'size'.
at javax.el.BeanELResolver.getBeanProperty(
at javax.el.BeanELResolver.getValue(
at javax.el.CompositeELResolver.getValue(
at com.sun.el.parser.AstValue.getValue(
at com.sun.el.parser.AstGreaterThan.getValue(
Truncated. see log file for complete stacktrace
Solution is to use Not Empty
<c:when test="${not empty actionBean.result}">

Monday, October 11, 2010