当前位置: 首页>>代码示例>>Java>>正文


Java BlockableQueue.setBlocking方法代码示例

本文整理汇总了Java中org.magnos.util.BlockableQueue.setBlocking方法的典型用法代码示例。如果您正苦于以下问题:Java BlockableQueue.setBlocking方法的具体用法?Java BlockableQueue.setBlocking怎么用?Java BlockableQueue.setBlocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.magnos.util.BlockableQueue的用法示例。


在下文中一共展示了BlockableQueue.setBlocking方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPeekInterrupt

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testPeekInterrupt()
{
	final AtomicReference<Thread> thread = new AtomicReference<Thread>();
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(500);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			thread.set(Thread.currentThread());
			assertNull( q.peek() );
		}
	});
	GroupTask.begin();
	
	sleep(100);
	
	thread.get().interrupt();
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:24,代码来源:TestBlockableQueue.java

示例2: testPollInterrupt

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testPollInterrupt()
{
	final AtomicReference<Thread> thread = new AtomicReference<Thread>();
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(500);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			thread.set(Thread.currentThread());
			assertNull( q.poll() );
		}
	});
	GroupTask.begin();
	
	sleep(100);
	
	thread.get().interrupt();
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:24,代码来源:TestBlockableQueue.java

示例3: testNonblocking

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testNonblocking()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(false);
	
	assertTrue( q.offer("Hello") );
	assertTrue( q.offer("World") );

	assertEquals( "Hello", q.peek() );
	assertEquals( "Hello", q.poll() );
	
	assertEquals( "World", q.peek() );
	assertEquals( "World", q.poll() );
	
	assertNull( q.poll() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:18,代码来源:TestBlockableQueue.java

示例4: testIsBlocking

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testIsBlocking()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	
	q.setBlocking(true);
	assertTrue( q.isBlocking() );
	
	q.setBlocking(false);
	assertFalse( q.isBlocking() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:12,代码来源:TestBlockableQueue.java

示例5: testPeekTimeout

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testPeekTimeout()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(100);
	
	assertNull( q.peek() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:10,代码来源:TestBlockableQueue.java

示例6: testPollTimeout

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testPollTimeout()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(100);
	
	assertNull( q.poll() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:10,代码来源:TestBlockableQueue.java

示例7: testWakeup

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testWakeup()
{
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			sleep(500);
			q.wakeup();
			sleep(500);
			q.wakeup();
		}
	});
	GroupTask.begin();
	
	watch.start("Before poll...");
	assertNull( null, q.poll() );
	watch.stop(" poll awoken (%.3f), done.\n");
	
	watch.start("Before peek...");
	assertNull( null, q.peek() );
	watch.stop(" peek awoken (%.3f), done.\n");
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:28,代码来源:TestBlockableQueue.java

示例8: testSingleReaderManyWriters

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testSingleReaderManyWriters()
{
	final int MESSAGES = 10000;
	final int WRITERS = 10;
	final int MESSAGES_PER_WRITER = MESSAGES / WRITERS;
	
	final AtomicInteger nullCounter = new AtomicInteger();
	final BlockableQueue<Integer> q = new BlockableQueue<Integer>();
	q.setBlocking(true);
	
	Runnable reader = new Runnable() {
		public void run() {
			int total = 0;
			double minWait = Double.MAX_VALUE;
			double maxWait = -Double.MAX_VALUE;
			Stopwatch watch = new Stopwatch();
			while (total < MESSAGES) {
				watch.start();
				Integer value = q.poll();
				watch.stop();
				if (value != null) {
					minWait = Math.min(minWait, watch.seconds());
					maxWait = Math.max(maxWait, watch.seconds());
					total++;	
				} else {
					nullCounter.incrementAndGet();
				}
			}
			System.out.format("Wait: min[%.6fs] max[%.6fs]\n", minWait, maxWait);
		}
	};
	
	Runnable writer = new Runnable() {
		public void run() {
			for (int i = 0; i < MESSAGES_PER_WRITER; i++) {
				assertTrue( q.offer(i) );
				// Causes the reader to wait some amount of time
				sleep(1);
			}
		}
	};
	
	GroupTask.initialize(WRITERS + 1);
	GroupTask.add(writer, WRITERS);
	GroupTask.add(reader);
	GroupTask.execute();
	
	System.out.println("Null polls: " + nullCounter.get());
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:51,代码来源:TestBlockableQueue.java

示例9: testSingleWriterManyReads

import org.magnos.util.BlockableQueue; //导入方法依赖的package包/类
@Test
public void testSingleWriterManyReads()
{
	final int MESSAGES = 10000;
	final int READERS = 10;
	final int MESSAGES_PER_READER = MESSAGES / READERS;

	final AtomicInteger nullCounter = new AtomicInteger();
	final BlockableQueue<Integer> q = new BlockableQueue<Integer>();
	q.setBlocking(true);
	
	Runnable reader = new Runnable() {
		public void run() {
			int total = 0;
			double minWait = Double.MAX_VALUE;
			double maxWait = -Double.MAX_VALUE;
			Stopwatch watch = new Stopwatch();
			while (total < MESSAGES_PER_READER) {
				watch.start();
				Integer value = q.poll();
				watch.stop();
				if (value != null) {
					minWait = Math.min(minWait, watch.seconds());
					maxWait = Math.max(maxWait, watch.seconds());
					total++;	
				} else {
					nullCounter.incrementAndGet();
				}
			}
			System.out.format("Wait: min[%.6fs] max[%.6fs]\n", minWait, maxWait);
		}
	};
	
	Runnable writer = new Runnable() {
		public void run() {
			for (int i = 0; i < MESSAGES; i++) {
				assertTrue( q.offer(i) );
			}
		}
	};
	
	GroupTask.initialize(READERS + 1);
	GroupTask.add(reader, READERS);
	GroupTask.add(writer);
	GroupTask.execute();
	
	System.out.println("Null polls: " + nullCounter.get());
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:49,代码来源:TestBlockableQueue.java


注:本文中的org.magnos.util.BlockableQueue.setBlocking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。