To start up customer java class or jar file when Java EE server starts. The solution usually is

1. Via WAR, servlet ; set the = 1 tag for servlet to provide intial invocation while the WAR is deployed.
Like this J2ee Start a class when application server starts

2. Depends on Java EE server setup.
For example, using weblogic startup and shutdown mechanism for EAR, In the weblogic-application.xml ; placed the following

//config xml

<startup>
<startup-class>MyStartup</startup-class>
<startup-uri>MyArchive.jar</startup-uri>
</startup>
<shutdown>
<shutdown-class>MyShutdown</shutdown-class>
<shutdown-uri>MyArchive.jar</shutdown-uri>
</shutdown>

I used second approach, so everytime I redeployed the EAR application the shutdown class main method was executed and then startup class invoked.

3. Using JBoss MBean service

Custom JMX MBeans in JBoss

ExampleHelloWorldService

How can an MBean depend on a SessionBean?

Writing JBoss MBean Services

Advertisements

Most of client server web applications we always have the same issue. How to easily convert client object to server side or reverse?
Here is some posts bring us something.

1. JPA implementation patterns: Service Facades and Data Transfers Objects

2. So, what’s the problem with JPA implementations?

3. Using GWT with Hibernate

1. Understanding the cache of TopLink Essentials(GlassFish JPA)

2. JPA 2.0 Caching

3. Understanding Caching in Hibernate, Part 1-3

4. OpenJPA Caching

5. Wiki: Java Persistence/Caching

6. JPA Under The Hood

7. Intro to Caching,Caching algorithms and caching frameworks, part 1-5

8. Hibernate: Truly Understanding the Second-Level and Query Caches

9. Hibernate Query Cache: A Dirty Little Secret

10. Writing Performant EJB Beans in the Java EE 5

This is very basic concept and useful at network stream programming.

1. Primitive Data Types

2. Bitwise and Bit Operators Shift

3. Wiki: Bitwise operation

4. Operators and Assignments – Java Bitwise Shift Operators

5. Java Bitwise Shift Operators

The JAXB XJC schema binding compiler transforms, or binds, a source XML schema to a set of JAXB content classes in the Java programming language.
But sometimes we need more specific stuff in the generated java class.
For exmaple, the JAXB2 Basics Plugins says “Schema compiler (XJC) produces schema-derived classes which can be used to turn XML into object structures and back. However, generated classes lack by default lack convenience and utility methods like equals(…), hashCode(…), toString() and so on.”

We can use Metro’s JAXB 2.0 commons project to save time.

Reference:
1. JAXB 2.0 commons project
2. Using JAX-WS With Maven
3. JAX-WS Metro and JBossWS
4. Java EE5 JAXB tutorial

There are two principal architectures for Web service interfaces: synchronous Web services and asynchronous Web services. These two architectures are distinguished by their request-response handling. With synchronous services, clients invoke a request on a service and then suspend their processing while they wait for a response. With asynchronous services, clients initiate a request to a service and then resume their processing without waiting for a response. The service handles the client request and returns a response at some later point, at which time the client retrieves the response and proceeds with its processing.

Let’s see some great articles about Asynchronous Web Service.
1. Web Service Interaction Architectures
2. Asynchronous operations and Web services, Part 1: A primer on asynchronous transactions
3. Asynchronous operations and Web services, Part 2
4. Can I call you back? – Asynchronous Web Services
5. Asynchronous Transactions and Web Services
6. Gerard Davison’s Asynchronous web service post

Since we talk about asynchronous web service, I will drill down the underlying basic,  SOAP over JMS. The W3C has just released W3C Candidate Recommendation. See InfoQ: SOAP Over Java Messaging Service.

1. Soap over JMS – what does it mean and why should I care?
2. Building a JMS Web service using SOAP over JMS and WebSphere Studio
3. Using Request-Response SOAP over JMS Web Services
4. SOAP over JMS with Axis2
5. SOAP Over JMS Interoperability

Update: 05-03-2010
1. Asynchronous web services with JBoss WS
2. Using Axis2 and Java for Asynchronous Web Service Invocation on the Client Side
3. Develop asynchronous Web services with Axis2
4. Really Simple Asynchronous Web Services

Recently I worked on a integration project threw read-timeout exception and blocking web service call. The client calls a EJB web service method to persistent an Entity Bean. Unfortunately this web service is implemented wihtin a long-running process and it causes JBoss transaction timeout.
The exception like this

This bug looks like easy, and I can just raise the JBoss’s jboss-service.xml Transaction Timeout value to higher.
But if you look down the details, you may find more interesting thing. Read more on Transaction Timeouts and EJB3/JPA and Using JBossJTA in Application Servers.

Although this might fix my problem of tansaction timeout, I still haven’t solved the performance issue from client calling the long-running process. Then I change the code inside of EJB web service. I crate a Message Driven Bean (MDB) and move the persistent Entity Bean there. Now the exposed web service method sends JMS message to MDB asynchronously and return to client fast. No more blocking web service call.

Reference:

Building a JMS Web service using SOAP over JMS and WebSphere Studio

pic0914

sometimes I need to debug program with multiple threads and complex codes. Or I work on analyzing and interpreting the JVM performance monitoring and diagnostics statistics. I need a sharp tool to do it. So I find most powerful kits to help.

1. An Introduction to Java Stack Traces
2. JDB Example: Generating a Thread Dump
3. How to debug a multithreaded java program
4. Schedule your own Java thread dumps
5. JDK Debugging Tools
6. JDK Tools and Utilities
7. Exercise basic command line debugging tools
8. Debug your Java code with ease using JPDA
9. IBM and SAP Open Source their JVM Diagnostics Tools
10. IBM Thread and Monitor Dump Analyzer for Java
11. Sun VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities.
12. Eclipse Test & Performance Tools Platform Project
13. Eclipse Tips: Debugging your multi thread application

The constraint programming technology has matured to the point where it is possible to isolate some essential features and offer them as libraries or embedded cleanly in general purpose host programming languages.
For example ILOG Solver is for planning or scheduling systems. Now I am trying to use Constraint Programming Satisfy (CPS) and domain specific language (DSL) at scheduling system.

Library
1. JaCoP – Java Constraint Programming solver
2. Cream: Class Library for Constraint Programming in Java
3. jOpt is an open source implementation of the Optimization Programming Language
4. JACK: A Java Constraint Kit
5. ILOG CP Optimizer
6. Koalog Constraint Solver
7. Open Source Constraint Programming Solvers Written in Java (collections)

Reference
1. Magazine: Journal of Scheduling
2. Constraint Programming in Java with JSolver (ILOG)
3. Course: CS 886: Topics in Artificial Intelligence: Constraint Programming
4. Course: Programming with Constraints: an Introduction
5. Course: CONSTRAINT PROGRAMMING
6. Course: Constraint Programming: Services
7. Book: Programming with constraints
8. Book: Handbook of constraint programming
9. Solving Sudokus in Java

1. Atomic

1.1 JDK API
1.2 Ensure Thread Safety On Single Values With Atomic Variables
1.3 The Atomic classes in Java 5
1.4 Going atomic

2. Life cycle of a thread – join, yield, sleep

2.1 Life Cycle of A Thread
2.2 Java Threads Tutorial
2.3 When to join threads
2.4 Threads join
2.5 when to switch threads with yield()
2.6 Thread.yield
2.7 Pausing the Current Thread (sleep)
2.8 Thread.sleep
2.9 The volatile keyword in Java
2.10
Managing volatility

3.Overall

3.1 Concurrency in JDK 5.0
3.2 Brian Goetz’s blog
3.3 Introduction to Java Concurrency and Multithreading
3.4 Concurrent Programming with J2SE 5.0
3.5 Introduction to Java 5 java.util.concurrent API
3.6 Java Language Specification (3rd): Threads and Locks
3.7 Java as a Concurrent Programming Language for Operating Systems and Related Courses
3.8 Java Synchronization and concurrency