New Objects Class
The new Objects class of the java.util package provides a fail-proof way for comparing two objects at runtime:- The
equals()
method of the Objects class does a reference comparison. - The
deepEquals()
method piggybacks on the first argument'sequals()
method definition.
Array.deepEquals()
is invoked on the objects. The new Objects class provides all the required static utility methods.New Classes to Operate on File System
Java SE 7 provides classes that greatly simplify the age old integration processes of one application dropping files at a predefined shared location and other application picking them up. Java 7 provides a new class WatchService that notifies any events that take place in the file system under the watch.The following steps create an asynchronous file-watcher service:
- Obtain the path from the File class.
Path fPath = new File(filePath).toPath();
- Obtain a handle to the Watch service from the file system.
dirWatcher = fPath.getFileSystem().newWatchService();
- Register which type of events you are interested in.
fPath.register(dirWatcher, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY);
- Wait for the event to happen.
try{ WatchKey key = dirWatcher.take(); }catch(InterruptedException ie){ return; }
The WatchKey class now has all the details of the event that occurred in the directory.
- Loop through Step 4 to continue receiving events.
New Classes for Concurrency Package
The Java SE team added a wide variety of new classes to Java 7 to cater to various concurrency functionalities. Most notable among them are the RecursiveAction and RecursiveTask classes, which simplify new algorithm development. Understanding the difference between heavyweight and lightweight processes will help you grasp the value of these new classes.- A heavyweight process gets a replica of the code, stack, and data from the parent process. You create a heavyweight process by invoking
fork()
. - A lightweight process gets its own stack and shares resources and data with other threads or the parent thread. The Unix Thread API standard (POSIX) provides methods to create a thread.
To code a recursive call, you must subclass either one of these classes and define the
compute()
method. The getRawResult()
method returns null for RecursiveAction and returns a value for RecursiveTask. The Java 7 documentation provides a simple example for each of these classes.
Комментариев нет:
Отправить комментарий
Примечание. Отправлять комментарии могут только участники этого блога.