javahowto

java.util.Properties and character encoding

java.util.Properties class (see Java SE 7 Javadoc) by default assumes ISO 8859-1 character encoding in reading and writing. So when a properties file is in other character encoding, you will see strange characters and behaviors. Properties class has no method or constructor that takes encoding or locale parameter. Fortunately, in Java SE 6, two new methods were added to allow for reading from java.io.Reader and writing to...

javahowto

Java Thread Pools and their Thread Dumps

When analysing a thead dump, if the thread is created with a custom thread name, we can easily trace it to where the thread pool is created by the unique thread name.Otherwise, we will have to guess which type of thread pool is created from the stack trace, and then search the usage of creation methods like newCachedThreadPool, newSingleThreadScheduledExecutor, newScheduledThreadPool, or newCachedThreadPool.When using...

javahowto

Java Applicatioin Process Hangs on Windows and Cached Thread Pool

The following java test app runs and terminates normally on Unix but hangs on Windows. import java.util.concurrent.*;public class ThreadPoolTest { private static ExecutorService es = Executors.newCachedThreadPool(); public static void main(String args[]) { es.submit(new Task("## running task 1...")); es.submit(new Task("## running task 2...")); System.out.println("## after tasks, in...

javahowto

How to Configure hprof in GlassFish 3.x

These are the steps to configure hprof profiler in GlassFish 3.x:1, Identify the target JVM to profile.  In most cases, it's the domain administration (DAS) JVM, but it can be other JVM such as another standalone server instance, or a cluster server instance.2, Edit $GLASSFISH_HOME/config/osgi.properties, locate org.osgi.framework.bootdelegation property, and append hprof classes to it, using , (comma) as the package separator.  Do...

javahowto

How to Configure hprof in JBoss AS7

These are the steps to configure hprof profiler in JBoss AS 7.x:1, Identify the target JVM to profile.  In most cases, it's the standalone server JVM, but it can be other JVM such as domain process controller, host controller, or individual server.2, For standalone server, edit $JBOSS_HOME/bin/standalone.conf, locate JBOSS_MODULES_SYSTEM_PKGS property, and append hprof classes to it, using , (comma) as the package separator.  This...

javahowto

How to Create Management and Application Users in JBoss AS7

JBoss AS7 is secured by default, which means you will have to create users before accessing services and components, such as admin console and remote EJB. $JBOSS_HOME/bin/add-user.sh, or add-user.bat is the tool for such purpose. By default it runs in interactive mode, and prompt for user name, password, user type, role, realm, etc. It also has a silent mode (-s, or --silent).For example, to create a management user, which can be used...

javahowto

How to Create Global Modules in JBoss AS7

In other Java application servers and previous versions of JBoss AS, there is the concept of common lib, where users can put shared libraries for use by all deployed apps. How to achieve the same effect in AS7 with modules and their dependency? The easiest (not necessarily the best) way is to create a global module for a collection of shared jars.1, Create a module directory structure: mkdir -p...

javahowto

JBoss AS7 Ant Tasks for Deploy and Undeploy

I want to use ant to control deploy and undeploy apps to JBoss AS 7 in a simple test. I know I could just have ant copy the WAR, jar, or EAR files to $JBOSS_HOME/standalone/deployments directory, but then I will have to wait till the app is fully initialized before accessing it. So I decided to write some simple ant targets using JBoss AS7 CLI commands.<?xml version="1.0"?><project name="test"...

javahowto

Standalone Java Client for JBoss AS 7.1.1

In this previous post, I created a sample Java standalone client connecting to JBoss AS 5 & 6. Now let's look at how to do it in JBoss AS 7.1.1.This sample application consists of a stateless EJB, its remote business interface and a standalone java client that looks up the EJB and invokes its business method.ClientIF.javapackage test;public interface ClientIF {public String clientHello();}ClientBean.javapackage test;import...

javahowto

ConcurrentHashMap Examples

4 steps when accessing a cache implemented with java.util.ConcurrentHashMap (javadoc):get the value from the ConcurrentMap;if null, assume it's the first access, and create the value;call putIfAbsent on the concurrentMap to store the new value;if return value is not null (it's rare but happens), use the return value as the golden copy, and discard the newly-created object.The following test class, SqrtTest, displays the square root of...

javahowto

How to Create POJO JavaBean Custom Resource in GlassFish

In addition to simple value custom resources, GlassFish also provides decent support for POJO JavaBean custom resources. The steps are very similar to String and primitive custom resources, except that you will need to provide your resource impl class and use a different GlassFish factory class. For example, suppose we need to implement a Person class:public class Person implements java.io.Serializable { private String firstName; ...