Java Articles

Using the WASService.exe Command

The WASService.exe command allows you to setup a Windows service for a WebSphere server. The command has its own idiosyncratic behavior. Best way to learn about the program is through actual examples.

Removing a Service

Removing a  service seems pretty easy:

wasservice -remove SERVICE_NAME

What this command considers as service name is not same as Windows. A service has two names in Windows. A display name and service name. You can find out more about these names by running this Windows command

sc query state= all

Note: Notice the space after “state=”. Without the space, the command will fail.

WebSphere service names usually contain “IBM”. So, you can view all registered WebSphere services by running this command:

sc query state= all  | findstr IBM

If Windows shows the service name (not the display name) as “IBMWAS70Service – myNode01”, then you need to use myNode01 as the service name for the wasservice command. That is, use the name after “-“. For example:

wasservice  -remove  myNode01

This is effectively same as running the command:

sc  delete "IBMWAS70Service – myNode01"

Adding a Service

The example below will show you how to add a service that has administrative security enabled.

wasservice -add myNode01 -serverName server1
  -profilePath C:\WebSphere70\profiles\AppSrv01
  -wasHome C:\WebSphere70
  -logRoot C:\WebSphere70\profiles\AppSrv01\logs\server1
  -startType automatic
  -stopArgs "-username wasadmin -password waspass"

This will create a Windows service called “IBMWAS70Service – myNode01” for WAS7 and “IBMWAS80Service – myNode01” in WAS8.

Note: that the entire stopArgs argument has to be within double quotes.

2 Comments

Will Java Be Around in Five Years?

Clearly as an employee of a company that makes a lot of it’s business on training and consulting for Java programming and technologies this is not a pleasant thought to entertain.  It also seems like a fairly somber topic for my first post to our company blog.  Unfortunately this is a question I’ve been asking myself over the past few years (as really anyone who works with technology should ask) and lately I’m a little more concerned about the possible answers and factors that allow you to arrive at those answers.

First, I think a little bit of history about why this has concerned me of late…

Back even before Sun was swallowed by Oracle I was commenting internally on a situation that was developing that I was somewhat concerned about.  The situation was a dispute between Sun and Apache around the efforts of Apache to create an open-source implementation of Java SE, Apache Harmony.

I won’t get into too many details but it basically came down to the fact that the Apache Harmony project was unable to get a copy of the “Java Compatibility Kit” or “JCK” which would be used to certify that the Apache Harmony implementation is fully compliant with the Java SE specification (a good description of the problem is available on Stephen Colebourne’s blog).  Sun was willing to provide Apache Harmony with a copy of the JCK but it’s license placed “field of use” restrictions on what users of Apache Harmony could use Harmony on.  Since the people at Apache are very serious about licensing and open source software they argued that Sun was basically violating the rules that they themselves set out for the Java Community Process (JCP) which stated that the lead of a JCP specification could not place any contractual restriction on the right of a licensee (in this case Harmony) to create or distribute independent implementations.

The entire issue Apache was correctly pointing out was that nobody was going to be able to create independent implementations of Java SE (and therefore just about anything Java) without accepting these limits that they would need to pass along to users of their implementation.

If it were just Apache that held this view it may not have had much impact because the JCP works with specifications by allowing members that are part of the various “Executive Committees” (currently Java ME and Java SE/EE) to vote on Java Specification Requests (JSRs) that are proposed to create Java specifications.  Since the JSR process is one of the things that makes the Java community so vibrant this is obviously an important process.

As this issue developed it was clear from the minutes of the JCP Executive Committees that the other EC members recognized this dispute was about more than just Sun v. Harmony and had broader implications.  In fact, it was pretty clear from the minutes that there was broad agreement with Apache from most EC members, including Oracle (pre takeover), that this dispute needed to be resolved and that Sun didn’t have many friends that were seeing it’s side. 

It had gotten so bad recently that on the recent Java EE 6 public review ballot, Apache actually voted no because it felt Sun was violating the agreements of the JCP and many other members of the Java SE/EE executive committee expressed concern about the issue, although only Apache voted no. 

In fact the US Department of Justice extended it’s period for reviewing proposed acquisitions for the Oracle acquisition of Sun apparently specifically to investigate the Java licensing issue.  Unfortunately it was not apparent publically that the issue was resolved or any closer to resolution before the merger completed.

This matters for the broader Java community because this issue will probably come to a head over Java SE 7.  Java SE 7 “features” are being developed in OpenJDK right now but there is no specification proposal.  OpenJDK is the “open source implementation of Java that we control” started by Sun and now Oracle.  Even though the argument could be made that OpenJDK is an “independent implementation” of Java SE it also allows Oracle to release the OpenJDK implementation as the official Java SE JSR implementation where they could reintroduce the restrictions on the compatibility kit.

Sun and now Oracle have not yet submitted any JSR for Java SE 7.  Based on the comments of many Java JCP board member companies on recent specifications like Java EE 6 I get the feeling that the Java SE 7 spec would actually be voted down if Oracle would not allow open source implementations to license the Java Compatibility Kit and therefore be “certified” without the restrictions.  This of course would make headlines nobody involved with Java would want. 

Now enter Google and Android…

The Android platform from Google is based on a subset of Apache Harmony recompiled into the “Dalvik” VM for mobile devices.  This provides support for Android applications to be written in Java but obviously does not go the route of Java ME (Mobile Edition) which is of course the “official way” Android could have done it.  This has resulted in Oracle suing Google in a case that could have the same implications for the Java community that Sun v. Microsoft did.

The unfortunate thing about the lawsuit is that according to some the Apache and Oracle camps may have been working recently to “finally certify Harmony with Oracle”.  Even though no resolution was made it was promising that this was still an active issue.  One has to wonder where the lawsuit puts the process of certifying Harmony.  What is interesting from the article link above is that Apache seemed to agree with Oracle that the actions taken by Google would threaten to fracture the Java community.

This would be unfortunate because mobile smartphones really have the promise to expand the reach of Java all over which was always the goal of Java but just now becoming the reality.

The Oracle v Google lawsuit itself is based around software patents and not directly the licensing issues of Harmony and Java SE.  I think this is more because Oracle feels that a lawsuit about patent infringement would be easier to try in court unlike the confusing maze of licensing issues from directly challenging Android using an unlicensed Harmony.

I won’t really comment much on the lawsuit itself because there are certainly lots of other opinions out there.  Some are touting it as the “final showdown” between software patents and open source.  Some feel that Oracle is simply trying to capitalize financially from acquiring Sun and Java.  Others are glad that Oracle is stepping up to defend Java.  James Gosling (creator of Java) also has some interesting thoughts although it seems like it is mostly “I could see this coming” when he was still working at Oracle before leaving recently.

I think I am somewhere in the middle.  I don’t think Google is totally faultless as it seems like they were just begging to get sued by the approach they took.  I also think that even if Oracle doesn’t get entirely what they want part of what they might have wanted to accomplish is to create uncertainty about the Android platform, which they certainly have done.

So finally, back to our original question, will Java be around in five years?…

After the Oracle v. Google lawsuit got me thinking more about this again some research caused some concerns and reassurances.

At first I was concerned with the fact that if you look at the summary of JCP JSRs by stage there are no JSRs in the early stages of proposal or early review.  Some research shows however that the number of JSRs has been declining for some time, probably due to a number of factors although the battle of Java licensing certainly has to be one of those factors.  Of course there did seem to be a steady-state of JSR work from 2004-2006 and since the Sun/Apache issue started 2005-2006 it could also be argued that it was part of the JSR decline.

It is clear that the JCP process itself is likely going to have some major changes.  There are notes in the May 2010 JCP EC minutes that the EC discussed the proposed future of the JCP process by Oracle although the discussion was a “private session” with no details except the general topic and the July 2010 minutes are not yet published.  Unfortunately I’m not sure that the Google lawsuit exactly bodes well for the possible future of what the JCP will be.

I’m also concerned that even though Java retains it’s spot as the most popular programming language there was significant downward movement since last July and Java only barely held on the top spot compared to C.  Certainly a headline of “Java is no longer the most popular language” is not the kind of headline that would help after the lawsuit and right about the time that JavaOne will convene for the first time under Oracle.

I think overall Java will be around in five years as too many companies, including Oracle itself, have too many products based on Java.  It is more just a question of what kind of shape it might be in.  The next few years will actually probably be on fire as the Java EE 6 specification is a great step forward in the simplification and power of Java much like Java EE 5 was.  We are also going to see many major vendors implementing Java EE 6 much faster than they did with Java EE 5 which will be good.

We will have to see if the statement “Oracle supports open source” is just lip service meant to buy time to retain complete ownership of Java.

I think this is something important to follow because it might throw a hiccup into the Java maturation process at exactly the time many companies are taking a second look at Java.  Hearing that there are “license disputes” that are preventing the Java specifications from moving forward would certainly throw some cold water on any plans to move to Java after previously deciding against it. 

Hopefully those reading this that may not have been aware of the issues and how there is an underlying thread among many of these developments have benefited from getting quickly up to speed.  I think there will hopefully be quite a bit of information about many of these issues at the JavaOne conference in mid-September.  Stay tuned here for what I think everyone will agree is hoped to be good news on this front after a summer of some troubling news.

 

Let’s Hope,

Stuart Smith

Java and Administration Lead

Web Age Solutions

 

Here is some useful information if you want more info:

Apache statement on the Sun/Apache dispute – http://www.apache.org/jcp/sunopenletter.html

History on the original Sun/Apache dispute (Stephen Colebourne’s blog) – http://www.jroller.com/scolebourne/entry/shedding_new_light_on_no

An article on the issue between Google Android and Oracle (pre-lawsuit) – http://www.theregister.co.uk/2010/06/09/harmony_android_oracle_apache/

JCP Executive Committee minutes – http://jcp.org/en/resources/EC_summaries

1 Comment

Oracle WebLogic Portal 10gR3 Programming Course Launched

We are proud to have released Oracle WebLogic Portal 10gR3 programming course. This 3 day course focuses primarily on the JSR 286 API. It also covers JSF portlet bridge based portlet development. Extensive hands on lab exercises accompany the lecture sessions. These labs are done using Oracle Enterprise Pack for Eclipse.

Links to the relevant pages:

  1. WA1922 WebLogic Portal 10.3 Programming Training
  2. Detailed outline

No Comments

Notes About Portlet Events in JSR 286

JSR 286 allows portlets to fire events and consume events. An event is first fired from the processAction method. Portlet container notifies a consumer portlet by invoking its processEvent method. A consumer portlet can also fire an event from the processEvent method.

There is no way to fire an event during the rendering phase.

For the event mechanism to work, you need to follow a few ground rules. This article discusses those.

Defining an Event

An event is first defined in portlet.xml. This definition has to exist for the portlet application of both the publisher and consumer.

An event has a namespace qualified name and a payload data type. For example:

<portlet-app …>

<event-definition>
    <qname xmlns:x="http://www.webagesolutions.com">x:was</qname>
    <value-type>com.mycom.address.model.Address</value-type>
</event-definition>
</portlet-app>

In this example, the qualified name of the event is as follows:

– Namespace URL is “http://www.webagesolutions.com”

– The local part is “was”

The Java class for the payload data is com.mycom.address.model.Address. We will discuss the requirements for this class shortly.

You can also define an event using a simple name instead of a qualified name.

<event-definition>
    <name>AddressEvent</name>
    <value-type>com.mycom.address.model.Address</value-type>
</event-definition>

This is not recommended. To avoid any naming conflict, you should always use the qualified name approach.

The Payload Class

The event payload class is declared using the <value-type> element in portlet.xml. This class can be a Java primitive class, such as String and Integer. If you wish to use your own class, it must conform to a few rules:

  1. Must implement java.io.Serializable
  2. Must have a JAXB binding. To quickly do that, use the @XmlRootElement annotation.

For example:

@XmlRootElement
public class Address implements Serializable {

//…

}

Firing an Event

The publisher portlet needs to declare all the events it will fire in portlet.xml.

<portlet>

    <supported-publishing-event>
        <qname xmlns:x="http://www.webagesolutions.com">x:was</qname>
    </supported-publishing-event>
</portlet>

The local part and namespace URL must be exactly as stated in the event definition.

To fire an event, you need to call the setEvent method of either the ActionResponse or EventResponse object.

For example:

public void processAction(ActionRequest request, ActionResponse response)
        throws PortletException, java.io.IOException {

    //…

    Address a = new Address();
    response.setEvent(
        new QName("http://www.webagesolutions.com", "was"), a);

}

Note how the namespace URI and local part of the QName object matches the event definition.

Consuming an Event

The consumer side needs to declare all the events it is interested in consuming.

<portlet>

<supported-processing-event>
    <qname xmlns:x="http://www.webagesolutions.com">x:was</qname>
</supported-processing-event>
</portlet>

The namespace and local part must match the event definition. Otherwise, the consumer will not be notified.

Develop the processEvent method. This will be automatically called when a matching event is fired.

public void processEvent(EventRequest request, EventResponse response)
        throws PortletException, IOException {
    Event e = request.getEvent();

    logger.info("Got an event.");
    logger.info("QName: " + e.getQName());
    logger.info("Name: " + e.getName());
    logger.info("Value type: " + e.getValue().getClass().getName());
   
    Address a = (Address) e.getValue(); //Get the payload
}

This method will print out something like this:

INFO: QName: {http://www.webagesolutions.com}was
INFO: Name: was
INFO: Value type: com.mycom.address.model.Address

In Conclusion

You need to be extra careful in making sure that the qualified name of an event is correct in every place. Otherwise, events will not be dispatched to the right consumer. Also make sure that the payload type is serializable and has a JAXB binding.

3 Comments

Generational GC in IBM JDK

IBM JDK 1.5 introduced the use of generational GC. Prior to that, the whole heap was divided into Large Object Area (LOA) and Small Object Area (SOA). No consideration was given to the age of an object.

Generational GC attempts to minimize the number of objects to be inspected during GC. It takes into account the age of the objects. The mechanism is similar to the generational GC of Sun HotSpot and JRockit. There are slight differences.

Enabling Generational GC

Generational GC is not enabled by default in IBM JDK 1.5. To enable it, use the gencon GC policy. This is done by adding the following command line argument.

-Xgcpolicy:gencon

Heap Partitions

Partitioning the heap in regions is key to minimizing the number of objects to be inspected during GC. When generational GC is enabled, the heap is divided into two spaces:

  1. The new space.
  2. The tenured space.

The new space is further divided into two zones:

  1. Allocate space.
  2. Survivor space.

image

 

Initially, the survivor space is completely empty. A new object is always created in the allocate space.

image

If when creating a new object an allocation failure takes place in the allocate space, a minor GC called scavenge is started. Scavenge works as follows.

image

All live objects from the allocate space are moved to the survivor space. The allocate space becomes completely empty of any live objects. The roles of the allocate and survivor spaces are then switched.

image

New objects are then created in the new allocate space.

If during scavenge, it is detected that a live object to be moved from the allocate space has survived N number of previous scavenge attempts, the object is moved to the tenured space instead. Where N is called the tenure age and is dynamically determined by the JVM.

image

It is expected that if an object has survived multiple scavenge attempts, it is probably a long lived object. There not much point is inspecting that object during every GC. By moving that object to the tenured space we reduce the number of objects to be inspected during a scavenge.

If after a scavenge and allocation failure continues in the new allocate space, the new area is grown.

If during tenuring, the tenured space has allocation failure a GC of the tenured space will be needed.

Setting Sizes

The –Xms and –Xmx options continue to set the total initial and maximum sizes of the heap.

To set the initial and maximum sizes of the new space, use the –Xmns and –Xmnx options. For example:

-Xms5m  -Xmns2m

The total initial heap size is 5MB. Out of which 2MB will be for new space. The remaining 3MB will be for the old space.

You can also set the initial and maximum size of the tenured (old) space using –Xmos and –Xmox. But, avoid setting both new and tenured space sizes. It is best to set the size of one space and let the system use the remaining heap for the other space.

To view the current sizes of various spaces, use the –verbose:sizes option. For example:

-verbosegc -Xms5m -Xgcpolicy:gencon -verbose:sizes –Xmns2m

This will output:

-Xmca32K        RAM class segment increment  
-Xmco128K       ROM class segment increment
-Xmns2M         initial new space size  
-Xmnx253764K    maximum new space size  
-Xms5M          initial memory size
-Xmos3M         initial old space size
-Xmox1015058K   maximum old space size
-Xmx1015058K    memory maximum
-Xmr16K         remembered set size
-Xmso32K        operating system thread stack size
-Xiss2K         java thread stack initial size
-Xssi16K        java thread stack increment
-Xss256K        java thread stack maximum size 

Understanding Generational Verbose GC Output

When a scavenge is performed, only the new or nursery area is collected. The verbose GC output looks like this.

<af type="nursery" id="1" timestamp="Jun 22 22:46:35 2010" intervalms="0.000"> 
  
  <minimum requested_bytes="16" />
  <time exclusiveaccessms="0.014" meanexclusiveaccessms="0.014" threads="0" lastthreadtid="0x00172F00" />
  <refs soft="3" weak="6" phantom="1" dynamicSoftReferenceThreshold="32" maxSoftReferenceThreshold="32" />
  <nursery freebytes="0" totalbytes="1048576" percent="0" />
  <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
    <soa freebytes="2871984" totalbytes="2988544" percent="96" />
    <loa freebytes="157184" totalbytes="157184" percent="100" />
  </tenured>
  <gc type="scavenger" id="1" totalid="1" intervalms="0.000">
    <flipped objectcount="8514" bytes="467600" />
    <tenured objectcount="0" bytes="0" />
    <finalization objectsqueued="1" />
    <scavenger tiltratio="50" />
    <nursery freebytes="463696" totalbytes="1048576" percent="44" tenureage="10" />
    <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
      <soa freebytes="2871984" totalbytes="2988544" percent="96" />
      <loa freebytes="157184" totalbytes="157184" percent="100" />
    </tenured>
    <time totalms="1.962" />
  </gc>
  <nursery freebytes="461648" totalbytes="1048576" percent="44" />
  <tenured freebytes="3029168" totalbytes="3145728" percent="96" >
    <soa freebytes="2871984" totalbytes="2988544" percent="96" />
    <loa freebytes="157184" totalbytes="157184" percent="100" />
  </tenured>
  <refs soft="3" weak="2" phantom="1" dynamicSoftReferenceThreshold="32" maxSoftReferenceThreshold="32" /> <time totalms="2.023" />
</af>

The af type and gc type clearly shows that it is a scavenge type GC.

The <nursery> element appears in three places. The first one shows to size of the new space and the amount of free space available. The second one shows the same metrics right after scavenge. The third one shows the metrics after the new object has been allocated (the object that could not be allocated earlier that resulted in an allocation failure). The sizes of the tenured space should not change before and after a scavenge.

The -Xtgc:excessiveGC option comes handy to detect any GC related performance problem. This will output the following after every GC.

excessiveGC: gcid="6" intimems="7.014" outtimems="284.637"
 percent="2.40" averagepercent="0.40" 

Here, intimems shows the amount of time spent doing the last GC (with GC id of 9). The outtimems parameter shows the interval between the last two GCs (GC id 8 and 9). The percent and averagepercent parameters show the percentage of the time spent doing GC compared to normal execution of the JVM.

By default, verbose GC output goes to native standard error file. The –Xverbosegclog option allows you to route verbose GC output to a different file. For example:

–Xverbosegclog:/tmp/gc.log

2 Comments