Java NIO Chapter1 Learning Tips

Source: Internet
Author: User
Reasons for low efficiency of 1.java.io


But In most cases, Java applications have not truly been I/O bound in the sense the operating system couldn ' t sh Uttle data fast enough to keep them busy. Instead, the JVMs have not been doing I/O efficiently. There ' s an impedance mismatch between the operating system and the Java stream-based I/O model. The operating system wants to move data in large chunks (buffers), often with the assistance of hardware Direct Memory ACC ESS (DMA). The I/O classes of the JVM like-operate on small pieces-single bytes, or lines of text. This means which operating system delivers buffers full of


Data this stream classes of java.io spend a lot of time breaking down to little pieces, often copying each piece bet Ween several layers of objects. The operating system wants to deliver data by the truckload. The java.io classes want to process data by the shovelful. NIO makes it easier to back the truck right up to where you can make direct use of the data (a Bytebuffer object).




Solution Overview in
2.NIO


The Java.nio package provides new abstractions to address this problem. The Channel and Selector classes in particular provide APIs to I/O services that generic not were reachable to JDK 1 .4. The TANSTAAFL principle still applies:you won ' do able to access every feature of every operating system, but these new Classes provide a powerful the new framework that encompasses the high-performance I/O features commonly on available Al operating systems today. Additionally, a new Service Provider Interface (SPI) is provided in JAVA.NIO.CHANNELS.SPI that allows you to plug in new T Ypes of channels and selectors without violating compliance with the specifications.


TANSTAAFL principle-----------There Ain ' t No Such Thing as A free lunch.





3.FileIO


In older operating systems, this usually meant issuing a command directly to the disk driver to read the needed disk Secto Rs. But in modern, paged operating systems, the filesystem takes-advantage of demand paging to bring data into memory.





3.1FileLocking


while the name "file locking" implies locking a entire file (and is often do), locking is usually available T a finer-grained level. File regions are usually locked, with granularity down to the byte level. Locks are associated with a particular file, beginning at a specific byte location within ' file and running for a spec Ific range of bytes. This is


important because it allows many processes to coordinate access to specific areas the a file without impeding other PR Ocesses working elsewhere in the file.


File locks are either advisory or mandatory. The former is used in the Most Unix and Unixlike system, while the latter was used in the Microsoft operating system.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.