Setting maximum heap size and changing other JVM parameters is a fairly common administration task.
JVM configuration might be changing quite often during application development, usually as a result of performance testing.

Typically JVM parameters have to be updated for all application servers in a cell or at least for application servers that belong to a particular cluster.

Conveniently, WebSphere Application Server (WAS) supports updating JVM parameters using its administration APIs, specifically, AdminConfig object. This is illustrated by the script below.

import sys

Change JVM heap size for all application servers in a cell
# New heap size is passed as a parameter to the script

# Get the string with config ids of all serves
# Iterate over all servers - config ids are separated by \n 
for server_confid in server_confids.split("\n"):
    server_type=AdminConfig.showAttribute(server_confid, "serverType")
    # we're changing the heap size for application servers - we want to exclude node agents, etc.
    if server_type == "APPLICATION_SERVER":
        server_name=AdminConfig.showAttribute(server_confid, "name")
        # this is the query to get JavaVirtualMachine configuration object for a particular server
        jvm_path="/Server:%s/JavaProcessDef:/JavaVirtualMachine:/" % server_name
        # "modify" accepts  a list of lists - each list contains name and value (odd choice I must say, why not use tuples?)
        AdminConfig.modify(jvm_confid, [["maximumHeapSize", max_heap_size]])

# Commit our changes to the repository

This post is part of the series on WebSphere Application Server administration. Please subscribe to our blog if you’d like to receive updates.

Note: We offer professional services in the area of WebSphere architecture, implementation and operations. If you’re looking for help with any of these tasks, please let us know.

5 thoughts on “WebSphere Administration: Setting Heap Size

  1. There is no question that the code you supply will work. There are, however, much easier ways to change JVM parameters — approaches that require a lot less string manipulation. If you want to change heap size, you could call one of several AdminTask methods.
    # Assume n holds the name of a node and s holds the name of a server in that node
    # those are names, NOT configuration IDs
    # n is not needed if the server name is unique within the cell

    AdminTask.setJVMInitialHeapSize( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -initialHeapSize ‘ + str( 384 ) + ‘ ]’ )
    AdminTask.setJVMMaxHeapSize( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -maximumHeapSize ‘ + str( 944 ) + ‘ ]’ )

    # or you could set a bunch of JVM properties in one call
    AdminTask.setJVMProperties( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -initialHeapSize ‘ + str( 384 ) + ‘ -maximumHeapSize ‘ + str( 944 ) + ‘ -verboseModeGarbageCollection true ‘ + ‘ ]’ )

  2. Kevin,
    Thanks for the tip. Using AdminTask is certainly shorter, but scripting it from scratch gives you more flexibility. Also, I was trying to give a good example of how to use AdminConfig, I think that the WAS documentation is lacking in this area.

  3. Alexander:

    As you pointed out in your response to Kevin, the documentation for the WebSphere Application Server Scripting objects is a bit lacking. ;-)

    Hence the need for a book like this “WebSphere Application Server Administration using Jython” (

    I was pleased to see that your example specifically verifies the serverType before changing the heapsize. I have seen too many scripts that don’t take that kind of thing into account.

    Instead of using split( ‘\n’ ) to separate the lines of text returned by the AdminConfig.list(), I prefer to use splitlines() string method, so my loops tend to look like this:

    # Iterate over all servers – config ids (1 per line)
    for serverID in AdminConfig.list( ‘Server’ ).splitlines() :

    And to answer your question:
    # (odd choice I must say, why not use tuples?)

    – tuples are a python construct/data structure.
    – Remember that the scripting object API must be usable by both Jacl, and Jython…


  4. Bob, thanks for all your comments, I will certainly check out the book.
    I still think that IBM python APIs are far from perfect to put it mildly. OK, they don’t want to use tuples, but what about dictionaries or keyword arguments? They should provide separate wrapper objects for python and JACL if the languages are so vastly different. Especially since JACL was deprecated.

  5. Pingback: ugg boots blog

Comments are closed.