Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.CARNet.hr!Iskon!garrison.bnet.hr!gregory.BNet.hr!not-for-mail From: Josip Almasi Newsgroups: comp.lang.java.programmer Subject: Re: Upload using java nio Date: Wed, 14 May 2014 13:46:14 +0200 Organization: B.net Hrvatska d.o.o. Lines: 35 Message-ID: References: <459ec56a-b369-4261-b819-a4f232362f74@googlegroups.com> NNTP-Posting-Host: cpe-94-253-176-38.zg.cable.xnet.hr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: gregory.bnet.hr 1400067974 32444 94.253.176.38 (14 May 2014 11:46:14 GMT) X-Complaints-To: abuse@globalnet.hr NNTP-Posting-Date: Wed, 14 May 2014 11:46:14 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <459ec56a-b369-4261-b819-a4f232362f74@googlegroups.com> Xref: csiph.com comp.lang.java.programmer:28472 On 05/13/2014 08:37 PM, William Lopes wrote: > Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/ > > My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name'] > > But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance. I gave up nio because it introduces a number of platform specific troubles. 'Troubles' being both OS and JVM impl dependent. You may get OOM with bogus description. IBM JVM gives more precise OOM explanation, like was it ENOMEM or ENOBUFS, which gives you more info on how to tune OS. Furthermore, there's just a few nio methods that actually utilize proper OS functions in order to avoid unnecessary transfer between kernel mem and userspace mem. IIRC, with sun jvm on linux, I've found exactly one nio method that actually does the job. And apache mina did not use it:> So neither did software using it, many many server software. (netty does though) I have no idea how android nio works. But as the man said, nio is not faster than io - it all depends on other threads and their synchronization. In your case, setProgress() is blocking and synchronized. Blocking = transfer waits for bar to render. Synchronized = slow. Recommendiation: Make a thread to update progress bar(s). Let it have non-blocking calls to update volatile/atomic internal counter(s). Use these calls instead of setProgress(). Make it sleep for 100-1000 ms, then render bar(s). Regards...