Atitit. Attilax Summary of high performance traverse text file lines

Source: Internet
Author: User

Atitit. High performance Traverse text file lines Attilax Summary

There are several common methods for file reading and writing 1

Usually io reads 2.5s 1

NiO reads Perhaps the higher the : 2

NIO is typically in Reactor mode, andAIO typically uses proactor mode 2

Java support for bio, NIO, AIO: 2

BIO, NIO, AIO Scenarios for analysis: 3

There are several common ways to read and write files:

1, Byte Read and write (inputstream/outputstream)

2, character reading (filereader/filewriter)

3, line read (bufferedreader/bufferedwriter)

File size : 110m

Line :: 55w

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

UsuallyioRead2.5s

Public Static void Main (string[] args) {

Substancesaharalookandfeel

Long T1=new Date (). GetTime ();

Filex FX=new Filex ();

FX. Readperline ("E:\\ui.rar.txt", "GBK", new scannerlinefilter4mail ());

System. out. println ("--f");

// list<string> Li = Filex.read2list_filtemptynstartspace ("C:\\em.txt");

System. out. println (new Date (). GetTime ()-T1);

}

Public class Scannerlinefilter4mail implements Closure {

int n= 0;

@Override

Public Object execute (Object arg0) throws Exception {

n+ +;

if (n%10000==0)

System. out. println ("-----:"+n);

//System.out.println (arg0);

return null;

}

Niothe higher the reading May be..

One result: NiO spends about one-third less than bio. (from site)

Niousually withReactormode,AIOusually withProactorMode

。 AIO simplifies programming, stream reads and writes are done by the OS, and does not need to traverse selector like NiO. Windows-based IOCP implementation Aio,linux only the Eppoll simulation implements AIO.

Prior to JAVA7, the JDK supported only NiO and bio and supported AIO from 7 onwards.

Java support for bio, NIO, Aio:

·

Java BIO: Synchronization and blocking, the server implementation mode for a connection to a thread, that is, the client has a connection request when the server needs to start a thread to process, if the connection does not do anything will cause unnecessary thread overhead, of course, can be improved through the thread pool mechanism.

·

·

Java NIO: Synchronous non-blocking, the server implementation mode is a request for a thread, that is, the connection request sent by the client is registered on the multiplexer, and the multiplexer polls to the connection with an I/O request to start a thread for processing.

·

·

Java AIO (nio.2): Asynchronous non-blocking, server implementation mode for a valid request for a thread, the client I/O requests are completed by the OS before notifying the server application to start the thread for processing,

·

BIO, NIO, AIO application scenario analysis:

·

The bio method is suitable for a small and fixed number of connections, which requires a high level of server resources, and is limited to applications, JDK1.4 the only choice before, but the program is intuitive and easy to understand.

·

·

The NIO approach is suitable for architectures with a large number of connections and short (light-operated) connections, such as chat servers, which are limited to applications, and are more complex to program, and JDK1.4 begin to support.

·

·

AIO mode allows for a number of connections and long-connected (re-operation) of the architecture, such as the album server, full call to the OS to participate in concurrent operations, programming more complex, JDK7 began to support.

·

Java NIO Series Tutorials - Special manuscript -iteye essence . htm

Java NIO and BIO Statistics file line number performance comparison - Open source China Community . htm

BIO, NIO, AIO(EXT) - Zhao Lei's blog -iteye technology website . htm

Java BIO,NIO,AIO Learning - power comes from the love of absolute sincerity! -51CTO technology blog . htm

Java NIO Series Tutorials - Special manuscript -iteye essence . htm

Atitit. Attilax Summary of high performance traverse text file lines

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.