java.nio.*

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ak

    java.nio.*

    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.OutOf MemoryError
    at java.nio.Bits.r eserveMemory(Un known Source)
    at java.nio.Direct ByteBuffer.<ini t>(Unknown Source)
    at java.nio.ByteBu ffer.allocateDi rect(Unknown Source)
    at sun.nio.ch.Util .getTemporaryDi rectBuffer(Unkn own Source)


  • S. Balk

    #2
    Re: java.nio.*

    > 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.


    Comment

    • Thomas Weidenfeller

      #3
      Re: java.nio.*

      "S. Balk" <s.balk@hccnet. n0spam.nl> writes:[color=blue]
      > am I the only one to say that the way you use the java.nio. is bullshit?[/color]

      No :-)

      Followup set to a more appropriate group.

      /Thomas

      Comment

      • Jordan Zimmerman

        #4
        Re: java.nio.*

        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




        Comment

        • iksrazal

          #5
          Re: java.nio.*

          "ak" <ak@me.com> wrote in message news:<3f448e86$ 1_2@news.tm.net .my>...[color=blue]
          > 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.OutOf MemoryError
          > at java.nio.Bits.r eserveMemory(Un known Source)
          > at java.nio.Direct ByteBuffer.<ini t>(Unknown Source)
          > at java.nio.ByteBu ffer.allocateDi rect(Unknown Source)
          > at sun.nio.ch.Util .getTemporaryDi rectBuffer(Unkn own Source)[/color]

          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

          Comment

          • Brian S O'Neill

            #6
            Re: java.nio.*

            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:3f448e86$1 _2@news.tm.net. my...[color=blue]
            > 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.OutOf MemoryError
            > at java.nio.Bits.r eserveMemory(Un known Source)
            > at java.nio.Direct ByteBuffer.<ini t>(Unknown Source)
            > at java.nio.ByteBu ffer.allocateDi rect(Unknown Source)
            > at sun.nio.ch.Util .getTemporaryDi rectBuffer(Unkn own Source)
            >
            >[/color]


            Comment

            • Roedy Green

              #7
              Re: java.nio.*

              On Sun, 24 Aug 2003 10:33:02 -0700, "Jordan Zimmerman"
              <jordanz@altura .com> wrote or quoted :
              [color=blue]
              >ByteBuffers[/color]
              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.

              Comment

              • Thomas G. Marshall

                #8
                Re: java.nio.*

                iksrazal <iksrazal@terra .com.br> horrified us with:

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

                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.


                Comment

                Working...