Mercurial > hg > Applications > TreeVNC
diff src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java @ 74:f1938dd3b518
don't heap space error.
author | oc |
---|---|
date | Mon, 28 Apr 2014 18:25:23 +0900 |
parents | 12c3a73be47f |
children | ef3586035d25 |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Mon Apr 28 18:25:23 2014 +0900 @@ -1,5 +1,6 @@ package jp.ac.u_ryukyu.treevnc; +import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; public class MulticastQueue<T> @@ -11,7 +12,40 @@ { tail = new Node<T>(null); } + + /** + * @param size + * @return + * + * try to allocate byteBuffer. + * wait until heap is available. + * + * + */ + public ByteBuffer allocate(int size) + { + ByteBuffer b=null; + while(true){ + try{ + b = ByteBuffer.allocate(size); + }catch(OutOfMemoryError e){ + System.err.println("multicastqueue : wait for heap : " + e); + } + if(b!=null){ + break; + } + try { + wait(); + } catch (InterruptedException e) { + } + } + return b; + } + public synchronized void heapAvailable() { + notifyAll(); + } + public synchronized void put(T item) { Node<T> next = new Node<T>(item); @@ -43,7 +77,6 @@ }catch(InterruptedException _e){ continue; } -// item = node.getItem(); item = next.getItem(); node = next; } while ( item == null);