473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

java.nio.*

ak
am I the only one to say that the java.nio. is bullshit?

i have been trying to write some code using it to transfer file over the
net.

small file it is ok, big file -- problematic.

java.lang.OutOfMemoryError
at java.nio.Bits.reserveMemory(Unknown Source)
at java.nio.DirectByteBuffer.<init>(Unknown Source)
at java.nio.ByteBuffer.allocateDirect(Unknown Source)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Unknown Source)
Jul 17 '05 #1
7 6666
> am I the only one to say that the java.nio. is bullshit?

am I the only one to say that the way you use the java.nio. is bullshit?

ok... you are trying to put a large file in memory, and the memory turns out
it isn't big enough. that's no problematic, that's what you should expect.
Jul 17 '05 #2
"S. Balk" <s.****@hccnet.n0spam.nl> writes:
am I the only one to say that the way you use the java.nio. is bullshit?


No :-)

Followup set to a more appropriate group.

/Thomas
Jul 17 '05 #3
There are bugs with nio in the 1.4.2 release. You need to go back to 1.4.1
or wait for a fix. Check the Bug Parade.

--
Jordan Zimmerman
http://www.jordanzimmerman.com

Jul 17 '05 #4
"ak" <ak@me.com> wrote in message news:<3f**********@news.tm.net.my>...
am I the only one to say that the java.nio. is bullshit?

i have been trying to write some code using it to transfer file over the
net.

small file it is ok, big file -- problematic.

java.lang.OutOfMemoryError
at java.nio.Bits.reserveMemory(Unknown Source)
at java.nio.DirectByteBuffer.<init>(Unknown Source)
at java.nio.ByteBuffer.allocateDirect(Unknown Source)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Unknown Source)


Two things:

1) This most likely is a heap problem. Try something like:

java -Xmx128m

Try both sides if neccesary.

2) The real advantage of nio is for sockets - previously you needed
one thread per connection.

iksrazal
Jul 17 '05 #5
I've played around with both the nio file APIs and socket APIs. Though
functional, they are buggy and much harder to use than they really need to
be. For memory mapped file I/O, I wrote my own simple native interface that
uses good ol' byte arrays. It's much simpler to use and I found it to be
faster too. For sockets I took the same approach, again with the same
approach. Easier and faster.

The problem with nio is that it is way overdesigned and imposes special
restrictions on how it is to be used. ByteBuffers, while convient when
writing certain kinds of applications, is a total PITA for anything else.
Try to implement a database or persistent hashtable using nio memory mapped
files. You'll find that sometimes the auto-moving cursor in the ByteBuffers
isn't the desired behavior. Try profiling the app and you'll see tons of
temporary objects being created as well as other useless work being
performed. ByteBuffers should have been designed as a higher level API. Byte
arrays offer much more flexibility.

In my opinion, nio is only good at writing only one application: a web
server. Open FileChannel, read chunks into direct ByteBuffer, flip, spew
contents out a SocketChannel. Even then, it won't scale that well on
platforms that support asyc socket I/O that has advanced beyond the
select/poll model.

It's also a pity that they rewrote the old socket API to use nio internally.
My applications that rely on the old sockets crash under load when running
all versions of jdk1.4. Jdk1.3.x is stable.

Whille nio is better than nothing, don't expect anything better to ever come
bundled with the jdk. We're stuck with it for the remaining lifetime of the
Java platform, and it sucks.
"ak" <ak@me.com> wrote in message news:3f**********@news.tm.net.my...
am I the only one to say that the java.nio. is bullshit?

i have been trying to write some code using it to transfer file over the
net.

small file it is ok, big file -- problematic.

java.lang.OutOfMemoryError
at java.nio.Bits.reserveMemory(Unknown Source)
at java.nio.DirectByteBuffer.<init>(Unknown Source)
at java.nio.ByteBuffer.allocateDirect(Unknown Source)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Unknown Source)

Jul 17 '05 #6
On Sun, 24 Aug 2003 10:33:02 -0700, "Jordan Zimmerman"
<jo*****@altura.com> wrote or quoted :
ByteBuffers

Is the point of ByteBuffers to deal with endian issues?
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #7
iksrazal <ik******@terra.com.br> horrified us with:

....[snippity doo dah]...
2) The real advantage of nio is for sockets - previously you needed
one thread per connection.


No, the real advantage of nio is in not having to use the ridiculous
decorator pattern x levels deep. It was both slow /and/ confusing. nio
fixes all that.
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.