<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smartkey - Java Software Consultancy &#187; Tomcat</title>
	<atom:link href="http://blog.smartkey.co.uk/tag/tomcat/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartkey.co.uk</link>
	<description></description>
	<lastBuildDate>Tue, 13 Dec 2011 15:03:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Address in Use Error using Tomcat on Windows XP</title>
		<link>http://blog.smartkey.co.uk/2010/09/bindexception-when-starting-tomcat/</link>
		<comments>http://blog.smartkey.co.uk/2010/09/bindexception-when-starting-tomcat/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 12:21:07 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=783</guid>
		<description><![CDATA[Occasionally you might get an error like this when launching Tomcat:
java.net.BindException: Address already in use: JVM_Bind &#60;null&#62;:8080
This can be caused if you already have Tomcat running as it will hold onto a network port for handling HTTP requests. In the above example the port shown is 8080.
However, this error is sometimes apparent even when Tomcat [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally you might get an error like this when launching Tomcat:</p>
<pre>java.net.BindException: Address already in use: JVM_Bind &lt;null&gt;:8080</pre>
<p>This can be caused if you already have Tomcat running as it will hold onto a network port for handling HTTP requests. In the above example the port shown is 8080.</p>
<p>However, this error is sometimes apparent even when Tomcat has already been shut down, expecially if you&#8217;ve shut it down abruptly. The problem here is that the Tomcat process may not have completely ended and that Windows is holding onto the network port for it.</p>
<p>To resolve this do the following:</p>
<ol>
<li>find the process ID that has the port reserved,</li>
<li>kill the process, releasing the port.</li>
</ol>
<h4>Step 1 &#8211; Find the process thats holding onto the port</h4>
<p>Start a command prompt and enter the command:</p>
<pre>netstat -ano</pre>
<p>The flags for this cause (a)  all connections and ports to be listed, (n) port numbers to be shown numerically, and importantly (o) which causes the process ID to be included in the output. The results of running this should look something like this:</p>
<pre class="brush: php">
Active Connections

Proto  Local Address          Foreign Address        State           PID
TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       496
TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
TCP    0.0.0.0:1776           0.0.0.0:0              LISTENING       1128
TCP    0.0.0.0:2864           0.0.0.0:0              LISTENING       2524
TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING       1708
TCP    0.0.0.0:3389           0.0.0.0:0              LISTENING       424
TCP    0.0.0.0:6942           0.0.0.0:0              LISTENING       2524
TCP    0.0.0.0:8008           0.0.0.0:0              LISTENING       1292
TCP    0.0.0.0:8009           0.0.0.0:0              LISTENING       2904
TCP    0.0.0.0:8012           0.0.0.0:0              LISTENING       1456
TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       2904
TCP    0.0.0.0:8443           0.0.0.0:0              LISTENING       2904
TCP    0.0.0.0:15000          0.0.0.0:0              LISTENING       1864
TCP    0.0.0.0:33115          0.0.0.0:0              LISTENING       704
TCP    0.0.0.0:63342          0.0.0.0:0              LISTENING       2524
TCP    10.136.38.94:139       0.0.0.0:0              LISTENING       4
</pre>
<p>In the output, port 8080 (under Local Address, on line 14) can be seen to belong to process ID (PID) 2904.</p>
<h4>Step 2 &#8211; Kill the process</h4>
<p>Press &lt;CTRL&gt;&lt;ALT&gt;&lt;DEL&gt; and then select Task Manager, then from the Task Manager choose the menus: View | Select Columns. In the dialog that appears check the PID checkbox to display the process ID and then dismiss it by pressing OK.</p>
<p>With the Processes tab selected you should be able to idenify the process with the PID that we found in step 1. In this example the value would be 2904.</p>
<p>Select this process and click End Process. Confirm that you want to kill the process and you should find that once it has been killed off, the network port it was holding has been released.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2010/09/bindexception-when-starting-tomcat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exposing Spring Beans as JMX Managed Beans in Tomcat</title>
		<link>http://blog.smartkey.co.uk/2008/10/exposing-spring-beans-as-jmx-managed-beans-in-tomcat/</link>
		<comments>http://blog.smartkey.co.uk/2008/10/exposing-spring-beans-as-jmx-managed-beans-in-tomcat/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 22:47:52 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[MBean]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=52</guid>
		<description><![CDATA[JMX provides a simple solution to application management. In this article, we&#8217;ll look at how Spring beans can be easily exported as a JMX MBean making their methods and properties available from a JMX client application, such as JConsole.
This technique has the following advantages:

Your Java bean&#8217;s methods can be triggered manually and interactively (great for [...]]]></description>
			<content:encoded><![CDATA[<p>JMX provides a simple solution to application management. In this article, we&#8217;ll look at how Spring beans can be easily exported as a JMX MBean making their methods and properties available from a JMX client application, such as JConsole.</p>
<p>This technique has the following advantages:</p>
<ul>
<li>Your Java bean&#8217;s methods can be triggered manually and interactively (great for application development and management)</li>
<li>Has minimal impact on the code you write (only annotations are used)</li>
<li>Simple to configure using Spring</li>
<li>Works for stand-alone applications and server based ones too (the following discussion demonstrates this using Tomcat)</li>
</ul>
<h3 style="margin-top: 18px;">What are JMX and Spring?</h3>
<p>JMX provides a standard means of accessing, and interacting with, objects within a running process. An object that exposes itself via JMX is known as an MBean, if you&#8217;re looking for a more detailed overview of JMX, try this excellent <a href="http://www-128.ibm.com/developerworks/java/library/j-jtp09196/index.html" target="_blank">introductory article on JMX</a> by Brian Goetz.</p>
<p><a href="http://www.smartkey.co.uk/www.springframework.org" target="_blank">Spring</a> is a comprehensive open-source framework which can greatly simplify the development of all types of Java applications</p>
<p>In this article, a basic understanding of both JMX and Spring is assumed.</p>
<h3>Configuring Spring</h3>
<p>There are a few ways of doing this. This is my favourite approach though as it is the least invasive to your Java code (as you&#8217;ll see later on) :</p>
<pre>&lt;!-- Expose all annotated beans as JMX MBeans --&gt;

&lt;bean id="exporter"

      lazy-init="false"
      p:autodetectModeName="AUTODETECT_ASSEMBLER"
      p:assembler-ref="assembler"
      p:namingStrategy-ref="namingStrategy"/&gt;

&lt;bean id="assembler"

      p:attributeSource-ref="annotationAttributeSource"/&gt;

&lt;bean id="namingStrategy"

      p:attributeSource-ref="annotationAttributeSource"/&gt;

&lt;bean id="annotationAttributeSource"
     /&gt;</pre>
<p>The <em>exporter</em> will identify which of your application classes should be exported as JMX beans. If your application classes support the JMX management interfaces then this class can be used to detect and export your beans automatically for you (just set the autoDetectModeName property to AUTODETECT_MBEAN).</p>
<p>A simpler approach, which relies on you simply annotating your POJO classes, is to configure the exporter to use an assembler (to identify which beans should be exported) and a naming strategy (to decide what names will be used for your beans when they are exported to the JMX server). Note in the above example how the <em>assembler</em> and <em>namingStrategy</em> properties have been set to use this approach.</p>
<p>Both the assembler and the namingStrategy delegate their method calls to the <em>annotationAttributeSource</em> bean (c.f. the Strategy design pattern) which examines the beans in the Spring context for annotations to determine whether the beans are to be exported and what their names should be respectively.</p>
<h3>Annotating Your Java Code</h3>
<p>So now that Spring is configured to look for annotated classes, all you need to do is annotate your classes to indicate whether they should be exported as JMX services:</p>
<pre>@ManagedResource(objectName="bean:name=BatchProcessor")
public class BatchProcessor {

    @ManagedOperation
    public void startBatch() {

    }
}</pre>
<p>The ManagedResource annotation indicates that this class should be exported, and the objectName attribute specifies the JMX bean name.</p>
<p>The ManagedOperation annotation should be used to indicate which methods on this class should be accessible via JMX; by default methods are not made available. Both of the above annotations allow for general information to be set too, for example a description of the bean or the method.</p>
<h3>Configuring the Java Runtime</h3>
<p>Any J2SE 5 (or later) runtime provides support for JMX. In order to use it, certain system properties must first be set.</p>
<p>For example, if you wanted to activate JMX in Tomcat, then you&#8217;d need to add these system properties to the start-up script:</p>
<pre>set CATALINA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false</pre>
<p>In this example, no security has been set for the Tomcat process. You should ensure that you configure JMX appropriately for your environment.</p>
<h3>Using JConsole to Access Your MBeans</h3>
<p>JConsole is an application that ships with the current JDK from Sun. It provides a graphical user interface for accessing JMX beans running in remote processes.</p>
<p>You can launch JConsole from the command line:</p>
<pre>$ jconsole</pre>
<p>When it starts, you&#8217;ll be asked to enter a URL for the JMX server you want to attach to. The above configuration specified that the JMX port should be 8086. If you&#8217;ve used the same configuration, then, once Tomcat has started, enter localhost:8086 and click on the Connect button.</p>
<p>Once connected, you can examine the JMX beans. Different versions on JConsole present these differently, the current version lists them under the MBeans tab, and under the beans node in the tree shown on the left. From here you can interactively invoke the methods on your beans and set or get their properties.</p>
<h3>Conclusion</h3>
<p>Exposing your application services in JMX provides a simple and effective means of accessing functionality that would only otherwise be available to the running application. This is particularly useful when manual intervention is sometimes required; for example, to manually launch a batch processor that&#8217;s embedded in the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2008/10/exposing-spring-beans-as-jmx-managed-beans-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

