A script enabled browser is required for this page to function properly.
Exit Print View

Oracle® Java Micro Edition Embedded Client Reference Guide, Version 1.0

Get PDF Book Print View

Document Information


Part I  Developer Guide

1.  Introduction

2.  Execution

3.  Developing Applications

Part II  Java Virtual Machine Reference

4.  Java Virtual Machine Capabilities

5.  Internal Memory Allocator

6.  Threading

6.1 Monitoring Java Threads Life-Cycle

6.2 Registering Callbacks

6.3 Thread Quota

6.4 Thread.stop Implementation

7.  Internationalization

8.  External PBP Porting Layer Plugin

Part III  Working Without An IDE

A.  Legacy Tools


Chapter 6


This chapter discusses basic threading tasks.

6.1 Monitoring Java Threads Life-Cycle

This feature is relevant for applications that invoke the JVM from a shared library (cvmi.dll for win32 or libcvm.so for Linux).

We have defined two types of callbacks that applications can register:

void (*JVMthreadStartHook_G)
     (char* name,int stackSize,char*groupName)
void (*JVMthreadEndHook_G)(char* name)

The JVMthreadStartHook_G is called when a Java thread starts execution and passes the application information about the thread (name, stack size and Java thread group name). The JVMthreadEndHook_G is called when the Java thread exits.

Applications can use these callbacks to monitor the life cycle of Java threads for debugging purposes.

6.2 Registering Callbacks

Use the following API to register your callbacks:

JVM_SetThreadRuntimeHooks( void 
    (*JVMthreadStartHook)(char* name,int stackSize, char *groupName),
    void (*JVMthreadEndHook)(char* name)); 

This API is defined in jni.h.

(Note: This extension to file jni.h can be obtained on request.)

For example:

void * myJVMthreadStartHook(char* name, int stackSize, 
                            char* groupName)
    printf("[JavaThread Created Name=%s,group=%s]\n"
            name, groupName == NULL ? "NULL" : groupName);

void myJVMthreadEndHook(char* name)
    printf("[JavaThread Destroyed Name=%s]\n", name);

In your application initialization code write:


6.3 Thread Quota

This feature supports limiting the number of Java threads that are alive at the same time. It is also possible to limit system threads and application threads. The definition of system thread is a thread whose class loader is the system class loader. Any other thread is an application thread.


The following properties configure quotas for system threads, application threads, and all threads (application + system) respectively:

In addition, the property java.lang.maxThreadControl should be set to “true” to activate thread quota.


./bin/cvm -Djava.lang.maxThreadControl=true 
    -jar myjar.jar 

This code limits the number of application threads to 50, and system threads to 100 while limiting the total number of threads to 100.

6.4 Thread.stop Implementation

The original Thread.stop() functionality (as well as Thread.suspend and Thread.resume) was marked as a deprecated method and removed from CDC some time ago.

Re-enabling the original methods would break TCK compliance, as it would mean addition of new public API. In order to achieve the functionality without jeopardizing compliance, a new class, sun.misc.ThreadControl has been implemented. This class provides the following static public APIs that act on supplied Thread objects:

public static void Thread.stop(Thread) 
public static void Thread.suspend(Thread) 
public static void Thread.resume(Thread) 

For example, to use Thread.stop(), an application developer could do the following;

Thread somethread;
<initialise and start thread>


To activate or deactivate this feature set the build-time flag CVM_THREAD_SUSPENSION. The current default is true.