Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / Database concepts.pdf
Скачиваний:
29
Добавлен:
12.05.2015
Размер:
6.96 Mб
Скачать

Java Overview

Figure 14–9 Java Component Structure

Java Server Applications

Oracle-Supported Java APIs:

SQLJ, JDBC

Java Core Class Libraries

Oracle Database JVM

Oracle Database Libraries

Operating System

Sun Microsystems furnishes publicly available specifications for both the Java language and the JVM. The Java Language Specification (JLS) defines things such as syntax and semantics; the JVM specification defines the necessary low-level behavior for the “machine” that executes the bytecodes. In addition, Sun Microsystems provides a compatibility test suite for JVM implementors to determine if they have complied with the specifications. This test suite is known as the Java Compatibility Kit (JCK). Oracle’s JVM implementation complies fully with JCK. Part of the overall Java strategy is that an openly specified standard, together with a simple way to verify compliance with that standard, allows vendors to offer uniform support for Java across all platforms.

Why Use Java in Oracle?

The only reason that you are allowed to write and load Java applications within the database is because it is a safe language. Java has been developed to prevent anyone from tampering with the operating system that the Java code resides in. Some

SQL, PL/SQL, and Java 14-39

Java Overview

languages, such as C, can introduce security problems within the database; Java, because of its design, is a safe language to allow within the database.

Although the Java language presents many advantages to developers, providing an implementation of a JVM that supports Java server applications in a scalable manner is a challenge. This section discusses some of these challenges.

Multithreading

Automated Storage Management

Footprint

Performance

Dynamic Class Loading

Multithreading

Multithreading support is often cited as one of the key scalability features of the Java language. Certainly, the Java language and class libraries make it simpler to write shared server applications in Java than many other languages, but it is still a daunting task in any language to write reliable, scalable shared server code.

As a database server, Oracle efficiently schedules work for thousands of users. The Oracle JVM uses the facilities of the RDBMS server to concurrently schedule Java execution for thousands of users. Although Oracle supports Java language level threads required by the JLS and JCK, using threads within the scope of the database will not increase your scalability. Using the embedded scalability of the database eliminates the need for writing shared server Java servers. You should use the database’s facilities for scheduling users by writing single-threaded Java applications. The database takes care of the scheduling between each application; thus, you achieve scalability without having to manage threads. You can still write shared server Java applications, but multiple Java threads does not increase your server’s performance.

One difficulty multithreading imposes on Java is the interaction of threads and automated storage management, or garbage collection. The garbage collector executing in a generic JVM has no knowledge of which Java language threads are executing or how the underlying operating system schedules them.

Non-Oracle9i model—A single user maps to a single Java language level thread; the same single garbage collector manages all garbage from all users. Different techniques typically deal with allocation and collection of objects of varying lifetimes and sizes. The result in a heavily shared server application is, at best, dependent upon operating system support for native threads, which can

14-40 Oracle9i Database Concepts

Java Overview

be unreliable and limited in scalability. High levels of scalability for such implementations have not been convincingly demonstrated.

Oracle9i JVM model—Even when thousands of users connect to the server and execute the same Java code, each user experiences it as if he is executing his own Java code on his own Java virtual machine. The responsibility of the Oracle JVM is to make use of operating system processes and threads, using the scalable approach of the Oracle RDBMS. As a result of this approach, the JVM’s garbage collector is more reliable and efficient because it never collects garbage from more than one user at any time.

Automated Storage Management

Garbage collection is a major feature of Java’s automated storage management, eliminating the need for Java developers to allocate and free memory explicitly. Consequently, this eliminates a large source of memory leaks that commonly plague C and C++ programs. There is a price for such a benefit: garbage collection contributes to the overhead of program execution speed and footprint. Although many papers have been written qualifying and quantifying the trade-off, the overall cost is reasonable, considering the alternatives.

Garbage collection imposes a challenge to the JVM developer seeking to supply a highly scalable and fast Java platform. The Oracle JVM meets these challenges in the following ways:

The Oracle JVM uses the Oracle scheduling facilities, which can manage multiple users efficiently.

Garbage collection is performs consistently for multiple users because garbage collection is focused on a single user within a single session. The Oracle JVM enjoys a huge advantage because the burden and complexity of the memory manager’s job does not increase as the number of users increases. The memory manager performs the allocation and collection of objects within a single session—which typically translates to the activity of a single user.

The Oracle JVM uses different garbage collection techniques depending on the type of memory used. These techniques provide high efficiency and low overhead.

Footprint

The footprint of an executing Java program is affected by many factors:

Size of the program itself—how many classes and methods and how much code they contain.

SQL, PL/SQL, and Java 14-41

Java Overview

Complexity of the program—the amount of core class libraries that the Oracle JVM uses as the program executes, as opposed to the program itself.

Amount of state the JVM uses—how many objects the JVM allocates, how large they are, and how many must be retained across calls.

Ability of the garbage collector and memory manager to deal with the demands of the executing program, which is often non-deterministic. The speed with which objects are allocated and the way they are held on to by other objects influences the importance of this factor.

From a scalability perspective, the key to supporting many concurrent clients is a minimum user session footprint. The Oracle JVM keeps the user session footprint to a minimum by placing all read-only data for users, such as Java bytecodes, in shared memory. Appropriate garbage collection algorithms are applied against call and session memories to maintain a small footprint for the user’s session. The Oracle JVM uses three types of garbage collection algorithms to maintain the user’s session memory:

Generational scavenging for short-lived objects

Mark and lazy sweep collection for objects that exist for the life of a single call

Copying collector for long-lived objects—objects that live across calls within a session

Performance

Oracle JVM performance is enhanced by implementing a native compiler.

How Native Compilers Improve Performance Java executes platform-independent bytecodes on top of a JVM, which in turn interacts with the specific hardware platform. Any time you add levels within software, your performance is degraded. Because Java requires going through an intermediary to interpret platform-independent bytecodes, a degree of inefficiency exists for Java applications that does not exists within a platform-dependent language, such as C. To address this issue, several JVM suppliers create native compilers. Native compilers translate Java bytecodes into platform-dependent native code, which eliminates the interpreter step and improves performance.

The following table describes two methods for native compilation.

14-42 Oracle9i Database Concepts

Java Overview

Native Compilation

 

Method

Description

 

 

Just-In-Time (JIT)

JIT compilers quickly compile Java bytecodes to native

Compilation

(platform-specific) machine code during runtime. This

 

does not produce an executable to be executed on the

 

platform; instead, it provides platform-dependent code

 

from Java bytecodes that is executed directly after it is

 

translated. This should be used for Java code that is run

 

frequently, which will be executed at speeds closer to

 

languages such as C.

Static Compilation

Static compilation translates Java bytecodes to

 

platform-independent C code before runtime. Then a

 

standard C compiler compiles the C code into an

 

executable for the target platform. This approach is more

 

suitable for Java applications that are modified

 

infrequently. This approach takes advantage of the mature

 

and efficient platform-specific compilation technology

 

found in modern C compilers.

 

 

Oracle uses static compilation to deliver its core Java class libraries: the ORB and JDBC code in natively compiled form. It is applicable across all the platforms Oracle supports, whereas a JIT approach requires low-level, processor-dependent code to be written and maintained for each platform. You can use this native compilation technology with your own Java code.

Dynamic Class Loading

Another strong feature of Java is dynamic class loading. The class loader loads classes from the disk (and places them in the JVM-specific memory structures necessary for interpretation) only as they are used during program execution. The class loader locates the classes in the CLASSPATH and loads them during program execution. This approach, which works well for applets, poses the following problems in a server environment:

SQL, PL/SQL, and Java 14-43

Соседние файлы в папке Oracle selected docs