Wednesday, December 3, 2014

How to increase Web Pool to handle more requests in JBoss AS7

Web Pool is important in an Application Server,
if it is not configure properly, the server performance would be affected when huge number of requests coming into the server.

By default, the web pool in JBoss is not created.
Below are the steps to create Web Pool in JBoss

Steps
1. open <JBoss_HOME>/standalone/configuration/standalone.xml

2. find subsystem for "urn:jboss:domain:threads:1.1"

3. add thread factory to the subsystem

<thread-factory name="http-connector-factory" thread-name-pattern="HTTP-%t" priority="9" group-name="uq-thread-pool"/>

4. create an executor in the subsystem

<unbounded-queue-thread-pool name="uq-thread-pool">
    <thread-factory name="http-connector-factory" />
    <max-threads count="10" />
    <keepalive-time time="30" unit="seconds" />
</unbounded-queue-thread-pool>

5. search for connector name="http"

6. bind the executor created in step 3 to the http connector

<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />

reference: https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Administration_and_Configuration_Guide/sect-Connector_Configuration.html


Done!!


Monday, November 17, 2014

How to replace HTML tag with ant

To replace a word or character with Ant,
we can use the following command.

<replaceregexp file="{FILE_TO_REPLACE}"
    match="{WORD_TO_REPLACE}"
    replace="{WORD}" flags="g" byline="true" />

But the above command can use to replace words withouth xml/html reserved characters only.
To replace words with xml/html reserved characters,

Steps:
1. encode the xml/html reserved words before putting into the the <replaceregexp /> command.
eg, <a>link</link>  =>  &lt;a&gt;link&lt;/a&gt;

2. put the encoded words into <replaceregexp />
eg,

<replaceregexp file="{FILE_TO_REPLACE}"
    match="&lt;a&gt;link&lt;/a&gt;"
    replace="&lt;a&gt;new_link&lt;/a&gt;" flags="g" byline="true" />


Done!!

Saturday, November 8, 2014

Scheduling with EJB

There is an easier way to schedule a job with EJB.
What we need is the EJB implementation and most important is the action method to be run.

@Stateless(name="serviceLookupName", mappedName="serviceLookupName")
public MyEjbServiceImpl {

    @Override
    @Schedule(dayOfMonth = "*", hour = "00", minute = "01")
    public void myScheduledMethod() {
       
        // action to run

    }
}


The advantage of this EJB schedule is easy to implement,
as just need to add the @Schedule annotation to an EJB method.

But the disadvantage is the scheduled time is hard to change,
if user wishes to change the time for the scheduler to run,
the source code need to be changed, recompile, and deploy.

for more information about the scheduler, please refer the official page.


Done!!

Thursday, November 6, 2014

reading java.util.List in velocity template

Assuming a list pass to the Velocity context.


List list = new ArrayList();
list.add("item1");
list.add("item2");
list.add("item3");

VelocityContext context = new VelocityContext();
context.put("list", list);


To get the list value,
below is the syntax in Velocity template

$list.get(0)

$list.get(1)

$list.get(2)


Done!!

Wednesday, November 5, 2014

How to convert sql date to util date


private String convertSqlDateToUtilDate(java.sql.Timestamp sqlDate) {

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

Calendar utilDate = Calendar.getInstance();

utilDate.setTimeInMillis(sqlDate.getTime());

return sdf.format(utilDate.getTime());

}

LinkWithin

Related Posts Plugin for WordPress, Blogger...