Click here to close now.




















Welcome!

Java IoT Authors: Carmen Gonzalez, Cloud Best Practices Network, Bob Gourley, Pat Romanski, Elizabeth White

Related Topics: Recurring Revenue, Java IoT, Microservices Expo, IBM Cloud

Recurring Revenue: Article

How to Diagnose Java Resource Starvation

Using the IBM Thread & Monitor Dump Analyzer for Java

We can visualize resource starvation using an elaborate rendition of the Dining Philosophers Problem. This classic metaphor of resource allocation among processes was first introduced in 1971 by Edsger Dijkstra in his paper "Hierarchical Ordering of Sequential Processes." It's been a model and universal method for verifying theories on resource allocation ever since.

The metaphor goes like this: There are three well-known philosophers in an Asian bistro. Dinner is served but they are only given three chopsticks because the restaurant's supply truck has been stuck in a snow storm for a couple of days. Naturally each philosopher needs two chopsticks to eat his dinner and each is protected from interference while he uses a chopstick.

Plato skipped lunch that day and insists that he should have priority or else he'll faint. If he doesn't give up his chopsticks, the other philosophers won't be able to eat and eventually they'll starve. If Plato drops his chopsticks and immediately picks them up before the other philosophers can get them then they won't be able to eat and they'll eventually starve.

Dijkstra's Dining Philosophers Problem employed spaghetti and forks but I used chopsticks and Asian cuisine for a more realistic illustration since you can't eat spaghetti with a single chopstick (see Figure 1).

These are examples of resource starvation. You could also encounter deadlock. There are a couple of solutions like semaphores and monitors. But we won't think about solutions or deadlocks in this article. We'll focus on detecting resource starvation using IBM Thread and Monitor Dump Analyzer for Java.

What Is the IBM Thread and Monitor Dump Analyzer for Java?
During the runtime of a Java process, some Java Virtual Machines (JVMs) may not respond predictably and often seem to hang up for a long time or indefinitely (until the JVM shuts down). It's sometimes very challenging to determine the root causes of these sorts of problems.

By triggering Java thread dumps or Javacores when a Java process doesn't respond, it's possible to collect diagnostic information related to the JVM and a Java application captured at a particular point during execution.

On some platforms, a Javacore is known as "javadump." The code that creates a Javacore is part of the JVM. One can control it by using environment variables and runtime switches. By default, a Javacore occurs when the JVM terminates unexpectedly. A Javacore can also be triggered by sending specific signals to the JVM. Although a Javacore or javadump can occur in Solaris JVMs, much of the content of the Javacore is added by IBM and, so, is present only in IBM JVMs.

IBM Thread and Monitor Dump Analyzer for Java analyzes thread dumps/Javacores and diagnoses monitor locks and thread activities to identify the root causes of hangs, deadlocks, and resource contention or monitor bottlenecks. It can analyze IBM, Solaris, and HP-UX Java thread dumps from Java Virtual Machine 1.3.1, 1.4.x, 5.0, and 6.0

More than three years ago, I created IBM Thread and Monitor Dump Analyzer for Java as a garage project and spent thousands of hours during weeknights, weekends, and vacations to provide my clients and colleagues with something that can help diagnose these problems easily, motivated by the same reasons as my other garage projects like IBM HeapAnalyzer, IBM Pattern Modeling and Analysis Tool, and IBM Performance Analyzer for Java for Windows. All the algorithms used have been filed with the U.S. Patent and Trademark Office.

The widgetry was introduced to the public about two years ago through alphaWorks where it's been one of the top downloads for 30 consecutive months. It's recorded 23,296 downloads so far and it's been used by more than 14,600 companies, government agencies, research facilities, and universities worldwide (these statistics are good as of October 2008).

What Is a Thread Dump?
A Java thread dump is the one of the traces/dumps that JVM provides to help diagnosis a hang, deadlock, or monitor contention issue. It contains diagnostic information related to the JVM and a Java application captured at a point during execution. For example, the information can be a list of all the threads that run on a Java virtual machine. Usually thread dumps have more than just thread information. Thread dumps can produce information about the operating system, application environment, threads, stacks, locks, and memory. IBM Thread Dumps/Javacores provide much more information like core interface, data conversion/unicode, class, diagnosis, execution management/thread management, lock, execution engine, mixed mode interpreter, JIT (Just-in-Time compiler), storage/JVM heap, and hardware portability interface/extended hardware portability interface.

The contents and formats of Java thread dumps depend on the platform you're running on and the JVM provider.

Since a thread dump's format isn't a part of the SDK specification, each SDK vendor provides a unique thread dump format and its own JVM information. Currently IBM Thread and Monitor Dump Analyzer for Java understands IBM, Solaris, and HP-UX Java thread dump formats.

By default, IBM JVM thread dumps occur when the JVM terminates unexpectedly. A thread dump can also be triggered by sending specific signals to the JVM. Thread dumps are usually human readable text. In an IBM JVM, the thread dump is often called a Javadump or Javacore. Javacore is NOT the same as a core file, which is generated by a system dump.

Before IBM Thread and Monitor Dump Analyzer for Java was introduced, people had to manually check hundreds of threads in the thread dumps using their favorite editors. With IBM Thread and Monitor Dump Analyzer for Java, we can easily diagnose a variety of issues without reading through hundreds of thread stack traces.

Usually thread dumps aren't as large as heap dumps. Usually its size is around 1MB or less unless you have large number of threads or classes. It's not a big deal to manually review thread dumps if you only have a handful of threads running on your JVM. If you have hundreds of threads with dozens of Java monitors, it gets complicated.

How Does It Work?
This technology analyzes the information in each thread and provides diagnostic information, such as current thread information, the signal that caused the Javacore/Java heap information (maximum Java heap size, initial Java heap size, garbage collector counter, allocation failure counter, free Java heap size, and allocated Java heap size), number of runnable threads, total number of threads, number of monitors locked, native memory usage of each JVM component, and deadlock information.

IBM Thread and Monitor Dump Analyzer for Java also provides you with the recommended size of the Java heap cluster (applicable only to IBM SDK 1.4.2 and 1.3.1 SR7 or above) based on a heuristic analysis engine.

It compares each Javacore and provides process ID information for threads, a time stamp of the first Javacore, a time stamp of the last Javacore, the number of garbage collections a minute, the number of allocation failures a minute, the time between the first Javacore and the last Javacore, the number of hang suspects, and a list of hang suspects.

This technology also compares all monitor information in a Javacore and detects deadlock and resource contention or monitor bottlenecks, if there are any.

Let's Get Started
We can simulate a starvation problem with a simple Java application.

In DiningPhilosophers.java, we created three chopsticks, c1, c2, and c3 with the names, chopstick 1, chopstick 2, and chopstick3. Then we created three philosophers, p1, p2, and p3 with the names, Socrates, Plato, and Aristotle. You might have noticed that each philosopher's name has a suffix that represents a priority since we want to give Plato more of a chance to eat. Besides a name and priority, each philosopher is also given a left chopstick and a right chopstick. We start with each philosopher, p1, p2,  and p3 as shown in Listing 1. (Download Listings 1-6 here.)

In Chopstick.java, we just create a constructor, a getter, and a setter for the name of chopstick as shown in Listing 2

In Philosopher.java, we create a constructor, getters and setters for right and left chopsticks, and the philosopher's name. We also override the run() method in which we acquire Java's built-in monitors for left and right chopsticks and call the eat() method. In each () method, we pause for two seconds to simulate eating with the sleep() method but keep in mind that the philosopher is eating, not sleeping in the eat() method. See Listing 3.

Now let's put all the classes in a subdirectory, compile, and run them.

Compiling classes on a Unix platform
javac com/ibm/Jinwoo/starvation/DiningPhilosophers.java

Compiling classes on a Windows platform
javac com\ibm\jinwoo\starvation\DiningPhilosophers.java

I used the latest release of IBM Java virtual machine 6.0 (build jvmwi3260-20080816_22093 VM build 20080816_022093_lHdSMr) and another vendor's latest release of a Java virtual machine 6.0 when I wrote this for a fair comparison.

Executing classes
java com.ibm.jinwoo.starvation.DiningPhilosophers
Plato priority9 is eating with chopstick 3 and chopstick 1
Plato priority9 is eating with chopstick 3 and chopstick 1
Plato priority9 is eating with chopstick 3 and chopstick 1
Plato priority9 is eating with chopstick 3 and chopstick 1
Plato priority9 is eating with chopstick 3 and chopstick 1

Most of the time Plato will be eating and the other two philosophers will have less of a chance to eat. We can generate thread dumps by sending signal 3 to the process. On the Windows platform, you can use keyboard combinations like Ctrl-Break to send signal 3 to a process running in a command line window. Listing 4 has the results from the IBM Java virtual machine.

We used another vendor's Java virtual machine and redirected output to a file.

Generating thread dumps with another vendor's Java virtual machine
java com.ibm.jinwoo.starvation.DiningPhilosophers 1> sun.log

Now let's talk about thread dump a little more. In most Java platforms, thread dumps are generated when the JVM terminates unexpectedly because of an operating system signal or when the user enters a reserved key combination control-break on Windows, say. We can also generate thread dumps with IBM's JavaDump API: com.ibm.jvm.Dump.JavaDump() if you're running a IBM Java virtual machine.

You can use the kill command on most Unix systems:

  • SIGQUIT[3] : JVM will not terminate

For example, kill -3 $PID

  • SIGSEGV[11] : JVM will terminate

For example, kill -11 $PID

On the IBM WebSphere Application Server 5/6 environment, you can use wsadmin script to generate thread dumps:

wsadmin.sh -conntype SOAP -port <port number>
> set jvm [$AdminControl completeObjectName type=JVM,process=server1,*]
> $AdminControl invoke $jvm dumpThreads

More Stories By Jinwoo Hwang

Jinwoo Hwang is a software engineer, inventor, author, and technical leader at IBM WebSphere Application Server Technical Support in Research Triangle Park, North Carolina. He joined IBM in 1995 and worked with IBM Global Learning Services, IBM Consulting Services, and software development teams prior to his current position at IBM. He is an IBM Certified Solution Developer and IBM Certified WebSphere Application Server System Administrator as well as a SUN Certified Programmer for the Java platform. He is the architect and creator of the following technologies:

Mr. Hwang is the author of the book C Programming for Novices (ISBN:9788985553643, Yonam Press, 1995) as well as the following webcasts and articles:

Mr. Hwang is the author of the following IBM technical articles:

  • VisualAge Performance Guide,1999
  • CORBA distributed object applet/servlet programming for IBM WebSphere Application Server and VisualAge for Java v2.0E ,1999
  • Java CORBA programming for VisualAge for Java ,1998
  • MVS/CICS application programming for VisualAge Generator ,1998
  • Oracle Native/ODBC application programming for VisualAge Generator ,1998
  • MVS/CICS application Web connection programming for VisualAge Generator ,1998
  • Java applet programming for VisualAge WebRunner ,1998
  • VisualAge for Java/WebRunner Server Works Java Servlet Programming Guide ,1998
  • RMI Java Applet programming for VisualAge for Java ,1998
  • Multimedia Database Java Applet Programming Guide ,1997
  • CICS ECI Java Applet programming guide for VisualAge Generator 3.0 ,1997
  • CICS ECI DB2 Application programming guide for VigualGen, 1997
  • VisualGen CICS ECI programming guide, 1997
  • VisualGen CICS DPL programming guide, 1997

Mr. Hwang holds the following patents in the U.S. / other countries:


Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal an...
Containers are not new, but renewed commitments to performance, flexibility, and agility have propelled them to the top of the agenda today. By working without the need for virtualization and its overhead, containers are seen as the perfect way to deploy apps and services across multiple clouds. Containers can handle anything from file types to operating systems and services, including microservices. What are microservices? Unlike what the name implies, microservices are not necessarily small, but are focused on specific tasks. The ability for developers to deploy multiple containers – thous...
Contrary to mainstream media attention, the multiple possibilities of how consumer IoT will transform our everyday lives aren’t the only angle of this headline-gaining trend. There’s a huge opportunity for “industrial IoT” and “Smart Cities” to impact the world in the same capacity – especially during critical situations. For example, a community water dam that needs to release water can leverage embedded critical communications logic to alert the appropriate individuals, on the right device, as soon as they are needed to take action.
The Internet of Things is in the early stages of mainstream deployment but it promises to unlock value and rapidly transform how organizations manage, operationalize, and monetize their assets. IoT is a complex structure of hardware, sensors, applications, analytics and devices that need to be able to communicate geographically and across all functions. Once the data is collected from numerous endpoints, the challenge then becomes converting it into actionable insight.
Manufacturing connected IoT versions of traditional products requires more than multiple deep technology skills. It also requires a shift in mindset, to realize that connected, sensor-enabled “things” act more like services than what we usually think of as products. In his session at @ThingsExpo, David Friedman, CEO and co-founder of Ayla Networks, will discuss how when sensors start generating detailed real-world data about products and how they’re being used, smart manufacturers can use the data to create additional revenue streams, such as improved warranties or premium features. Or slash...
While many app developers are comfortable building apps for the smartphone, there is a whole new world out there. In his session at @ThingsExpo, Narayan Sainaney, Co-founder and CTO of Mojio, will discuss how the business case for connected car apps is growing and, with open platform companies having already done the heavy lifting, there really is no barrier to entry.
As more intelligent IoT applications shift into gear, they’re merging into the ever-increasing traffic flow of the Internet. It won’t be long before we experience bottlenecks, as IoT traffic peaks during rush hours. Organizations that are unprepared will find themselves by the side of the road unable to cross back into the fast lane. As billions of new devices begin to communicate and exchange data – will your infrastructure be scalable enough to handle this new interconnected world?
Through WebRTC, audio and video communications are being embedded more easily than ever into applications, helping carriers, enterprises and independent software vendors deliver greater functionality to their end users. With today’s business world increasingly focused on outcomes, users’ growing calls for ease of use, and businesses craving smarter, tighter integration, what’s the next step in delivering a richer, more immersive experience? That richer, more fully integrated experience comes about through a Communications Platform as a Service which allows for messaging, screen sharing, video...
Consumer IoT applications provide data about the user that just doesn’t exist in traditional PC or mobile web applications. This rich data, or “context,” enables the highly personalized consumer experiences that characterize many consumer IoT apps. This same data is also providing brands with unprecedented insight into how their connected products are being used, while, at the same time, powering highly targeted engagement and marketing opportunities. In his session at @ThingsExpo, Nathan Treloar, President and COO of Bebaio, will explore examples of brands transforming their businesses by t...
The 3rd International WebRTC Summit, to be held Nov. 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA, announces that its Call for Papers is now open. Topics include all aspects of improving IT delivery by eliminating waste through automated business models leveraging cloud technologies. WebRTC Summit is co-located with 15th International Cloud Expo, 6th International Big Data Expo, 3rd International DevOps Summit and 2nd Internet of @ThingsExpo. WebRTC (Web-based Real-Time Communication) is an open source project supported by Google, Mozilla and Opera that aims to enable bro...
WebRTC has had a real tough three or four years, and so have those working with it. Only a few short years ago, the development world were excited about WebRTC and proclaiming how awesome it was. You might have played with the technology a couple of years ago, only to find the extra infrastructure requirements were painful to implement and poorly documented. This probably left a bitter taste in your mouth, especially when things went wrong.
SYS-CON Events announced today the Containers & Microservices Bootcamp, being held November 3-4, 2015, in conjunction with 17th Cloud Expo, @ThingsExpo, and @DevOpsSummit at the Santa Clara Convention Center in Santa Clara, CA. This is your chance to get started with the latest technology in the industry. Combined with real-world scenarios and use cases, the Containers and Microservices Bootcamp, led by Janakiram MSV, a Microsoft Regional Director, will include presentations as well as hands-on demos and comprehensive walkthroughs.
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
With the Apple Watch making its way onto wrists all over the world, it’s only a matter of time before it becomes a staple in the workplace. In fact, Forrester reported that 68 percent of technology and business decision-makers characterize wearables as a top priority for 2015. Recognizing their business value early on, FinancialForce.com was the first to bring ERP to wearables, helping streamline communication across front and back office functions. In his session at @ThingsExpo, Kevin Roberts, GM of Platform at FinancialForce.com, will discuss the value of business applications on wearable ...
In his session at @ThingsExpo, Lee Williams, a producer of the first smartphones and tablets, will talk about how he is now applying his experience in mobile technology to the design and development of the next generation of Environmental and Sustainability Services at ETwater. He will explain how M2M controllers work through wirelessly connected remote controls; and specifically delve into a retrofit option that reverse-engineers control codes of existing conventional controller systems so they don't have to be replaced and are instantly converted to become smart, connected devices.
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo, November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be.
SYS-CON Events announced today that Pythian, a global IT services company specializing in helping companies leverage disruptive technologies to optimize revenue-generating systems, has been named “Bronze Sponsor” of SYS-CON's 17th Cloud Expo, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Founded in 1997, Pythian is a global IT services company that helps companies compete by adopting disruptive technologies such as cloud, Big Data, advanced analytics, and DevOps to advance innovation and increase agility. Specializing in designing, imple...
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome,” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
With the proliferation of connected devices underpinning new Internet of Things systems, Brandon Schulz, Director of Luxoft IoT – Retail, will be looking at the transformation of the retail customer experience in brick and mortar stores in his session at @ThingsExpo. Questions he will address include: Will beacons drop to the wayside like QR codes, or be a proximity-based profit driver? How will the customer experience change in stores of all types when everything can be instrumented and analyzed? As an area of investment, how might a retail company move towards an innovation methodolo...