當前位置: 首頁>>代碼示例>>Java>>正文


Java NumberHelper.round方法代碼示例

本文整理匯總了Java中org.openyu.commons.lang.NumberHelper.round方法的典型用法代碼示例。如果您正苦於以下問題:Java NumberHelper.round方法的具體用法?Java NumberHelper.round怎麽用?Java NumberHelper.round使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openyu.commons.lang.NumberHelper的用法示例。


在下文中一共展示了NumberHelper.round方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stressReturn

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
public void stressReturn(String userId, byte[] bytes) {
	//
	messageCounter.incrementAndGet();
	byteCounter.addAndGet(ByteHelper.toByteArray(userId).length);
	byteCounter.addAndGet(bytes.length);
	//
	long end = System.currentTimeMillis();
	long dur = (end - returnBeg);
	double result = NumberHelper.round(byteCounter.get()
			/ (double) dur, 2);
	double kresult = NumberHelper.round(
			(byteCounter.get() / (double) 1024)
					/ (dur / (double) 1000), 2);
	double mbresult = NumberHelper.round((byteCounter.get()
			/ (double) 1024 / (double) 1024)
			/ (dur / (double) 1000), 2);
	//
	System.out.println("send/receive: " + messageCounter.get()
			+ " messages, " + byteCounter.get() + " bytes / " + dur
			+ " ms. = " + result + " BYTES/MS, " + kresult
			+ " K/S, " + mbresult + " MB/S");
}
 
開發者ID:mixaceh,項目名稱:openyu-socklet,代碼行數:23,代碼來源:BenchmarkJavaConnectorImplTest.java

示例2: stressReturn

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
public void stressReturn(String userId, byte[] bytes) {
	if (beg == 0) {
		beg = System.currentTimeMillis();
	}
	//
	messageCounter.incrementAndGet();
	byteCounter.addAndGet(ByteHelper.toByteArray(userId).length);
	byteCounter.addAndGet(bytes.length);
	//
	long end = System.currentTimeMillis();
	long dur = (end - beg);
	double result = NumberHelper.round(byteCounter.get() / (double) dur, 2);
	double kresult = NumberHelper.round((byteCounter.get() / (double) 1024) / (dur / (double) 1000), 2);
	double mbresult = NumberHelper
			.round((byteCounter.get() / (double) 1024 / (double) 1024) / (dur / (double) 1000), 2);
	//
	System.out.println("receive: " + messageCounter.get() + " messages, " + byteCounter.get() + " bytes / " + dur
			+ " ms. = " + result + " BYTES/MS, " + kresult + " K/S, " + mbresult + " MB/S");
	//
	sendStressReturn(userId, bytes);
}
 
開發者ID:mixaceh,項目名稱:openyu-socklet,代碼行數:22,代碼來源:FourSymbolSocklet.java

示例3: printResult

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * 印出結果
 * 
 * @param beg
 * @param byteCounter
 * @param timesCounter
 */
protected static void printResult(long beg, AtomicLong byteCounter, AtomicLong timesCounter) {
	long end = System.currentTimeMillis();
	long dur = (end - beg);
	double result = NumberHelper.round(byteCounter.get() / (double) dur, 2);
	double kresult = NumberHelper.round((byteCounter.get() / (double) 1024) / (dur / (double) 1000), 2);
	double mbresult = NumberHelper
			.round((byteCounter.get() / (double) 1024 / (double) 1024) / (dur / (double) 1000), 2);
	//
	System.out.println(timesCounter.get() + " rows, " + byteCounter.get() + " bytes / " + dur + " ms. = " + result
			+ " BYTES/MS, " + kresult + " K/S, " + mbresult + " MB/S");
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:19,代碼來源:BaseTestSupporter.java

示例4: printBean

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * Prints the beans.
 */
protected static void printBean() {
	AssertHelper.notNull(applicationContext, "The ApplicationContext must not be null");
	//
	String[] beanNames = applicationContext.getBeanDefinitionNames();
	Arrays.sort(beanNames, Collator.getInstance(java.util.Locale.ENGLISH));
	final String MSG_PATTERN = "#.{0} {1} \"{2}\"";
	// 計算所耗費的記憶體(bytes)
	RuntimeHelper.gc();
	// 原本的記憶體
	long memory = RuntimeHelper.usedMemory();
	//
	StopWatch sw = new StopWatch("Spring beans");
	// System.out.println("=========================================");
	// System.out.println("Spring beans");
	// System.out.println("=========================================");
	for (int i = 0; i < beanNames.length; i++) {
		String className = null;
		String name = beanNames[i];
		sw.start("#." + (i + 1) + " " + name);
		Object bean = null;
		try {
			// when abstract bean will throw exception
			// so set bean="abstract bean"
			bean = applicationContext.getBean(beanNames[i]);
			if (bean == null) {
				className = "NULL CLASS";
			} else {
				className = bean.getClass().getSimpleName();
			}
		} catch (Exception ex) {
			className = "ABSTRACT CLASS";
		}
		sw.stop();
		sw.printResult();

		// StringBuilder msg = new
		// StringBuilder(MessageFormat.format(MSG_PATTERN, (i + 1),
		// className, beanNames[i]));

		// 不是抽象類別
		// if (!abstractBean) {
		// System.out.println(msg);// 顯示黑色
		// } else {
		// System.err.println(msg);// 顯示紅色
		// }

		// System.out.println(msg);
		//
		usedMemory = Math.max(usedMemory, (RuntimeHelper.usedMemory() - memory));
	}
	long durTime = endTime - begTime;
	//
	RuntimeHelper.gc();
	usedMemory = Math.max(usedMemory, (RuntimeHelper.usedMemory() - memory));
	double kb = NumberHelper.round(ByteUnit.BYTE.toKiB(usedMemory), 1);
	double mb = NumberHelper.round(ByteUnit.BYTE.toMiB(usedMemory), 1);
	double sizeOf = NumberHelper.round(ByteUnit.BYTE.toMiB(MemoryHelper.sizeOf(applicationContext)), 1);
	//
	System.out.println("=========================================");
	final String MEMORY_PATTERN = "count: {0}, time: {1} mills., {2} bytes, {3} KB, {4} MB, sizeOf: {5} MB memory used";
	StringBuilder msg = new StringBuilder(
			MessageFormat.format(MEMORY_PATTERN, beanNames.length, durTime, usedMemory, kb, mb, sizeOf));
	System.out.println(msg);
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:68,代碼來源:BaseTestSupporter.java

示例5: main

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * 從main直接啟動
 * 
 * class path
 * 
 * org/openyu/socklet/bootstrap/client/applicationContext-client1.xml
 * 
 * @param args
 */
public static void main(String args[]) {
	try {
		if (started) {
			throw new IllegalStateException(new StringBuilder().append(ClientBootstrap.class.getSimpleName())
					.append(" was already started").toString());
		}
		//
		double usedMemory = 0d;
		long begTime = System.currentTimeMillis();
		// 計算所耗費的記憶體(bytes)
		RuntimeHelper.gc();
		// 原本的記憶體
		long memory = RuntimeHelper.usedMemory();
		// 建構applicationContext
		buildApplicationContext(args);

		// 建構客戶端控製器
		buildClientControl();
		// 建構客戶端服務
		buildClientService();
		// --------------------------------------------------
		// 啟動
		doStart();
		// --------------------------------------------------
		long endTime = System.currentTimeMillis();
		long durTime = endTime - begTime;
		//
		RuntimeHelper.gc();
		usedMemory = Math.max(usedMemory, (RuntimeHelper.usedMemory() - memory));
		double kb = NumberHelper.round(ByteUnit.BYTE.toKiB(usedMemory), 1);
		double mb = NumberHelper.round(ByteUnit.BYTE.toMiB(usedMemory), 1);
		double sizeOf = NumberHelper.round(ByteUnit.BYTE.toMiB(MemoryHelper.sizeOf(applicationContext)), 1);
		//
		if (started) {
			String MEMORY_PATTERN = "[{0}] start in {1} ms, {2} bytes , {3} KB, {4} MB, sizeOf: {5} MB memory used";
			StringBuilder msg = new StringBuilder(
					MessageFormat.format(MEMORY_PATTERN, id, durTime, usedMemory, kb, mb, sizeOf));
			LOGGER.info(msg.toString());
			//
			// ThreadHelper.loop(50);
		} else {
			LOGGER.error("[" + id + "] started fail");
		}

	} catch (Exception e) {
		clientControl.setVisible(false);
		LOGGER.error(new StringBuilder("[" + id + "] Exception encountered during main()").toString(), e);
		// 結束
		System.exit(0);
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-socklet,代碼行數:61,代碼來源:ClientBootstrap.java

示例6: main

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * 從main直接啟動,並不是在web下啟動
 * 
 * class path
 * 
 * org/openyu/socklet/bootstrap/server/applicationContext-slave1.xml
 * 
 * ThreadHelper.loop(50);
 * 
 * @param args
 */
public static void main(String args[]) {
	try {
		if (started) {
			throw new IllegalStateException(new StringBuilder().append(AcceptorBootstrap.class.getSimpleName())
					.append(" was already started").toString());
		}
		//
		double usedMemory = 0d;
		long begTime = System.currentTimeMillis();
		// 計算所耗費的記憶體(bytes)
		RuntimeHelper.gc();
		// 原本的記憶體
		long memory = RuntimeHelper.usedMemory();

		// 建構applicationContext
		buildApplicationContext(args);

		// 取得接受器服務
		buildAcceptorService();

		// 啟動
		doStart();
		//
		long endTime = System.currentTimeMillis();
		long durTime = endTime - begTime;
		//
		RuntimeHelper.gc();
		usedMemory = Math.max(usedMemory, (RuntimeHelper.usedMemory() - memory));
		double kb = NumberHelper.round(ByteUnit.BYTE.toKiB(usedMemory), 1);
		double mb = NumberHelper.round(ByteUnit.BYTE.toMiB(usedMemory), 1);
		double sizeOf = NumberHelper.round(ByteUnit.BYTE.toMiB(MemoryHelper.sizeOf(applicationContext)), 1);
		//
		if (started) {
			String MEMORY_PATTERN = "[{0}] ({1}) ({2}) start in {3} ms, {4} bytes, {5} KB, {6} MB, sizeOf: {7} MB memory used";
			StringBuilder msg = new StringBuilder(MessageFormat.format(MEMORY_PATTERN, id, instanceId, outputId,
					durTime, usedMemory, kb, mb, sizeOf));
			LOGGER.info(msg.toString());
			// loop
			ThreadHelper.loop(50);
		} else {
			LOGGER.error("[" + id + "] (" + instanceId + ") (" + outputId + ") started fail");
		}
	} catch (Exception e) {
		started = false;
		LOGGER.error(new StringBuilder("Exception encountered during main()").toString(), e);
		// 結束
		System.exit(0);
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-socklet,代碼行數:61,代碼來源:AcceptorBootstrap.java

示例7: start

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * 從web上啟動,或其他已經建構的applicationContext來啟動
 * 
 * @param applicationContext
 */
public static void start(ApplicationContext applicationContext) {
	AssertHelper.notNull(applicationContext, "The ApplicationContext must not be null");
	//
	try {
		if (started) {
			throw new IllegalStateException(new StringBuilder().append(AcceptorBootstrap.class.getSimpleName())
					.append(" was already started").toString());
		}
		double usedMemory = 0d;
		long begTime = System.currentTimeMillis();
		// 計算所耗費的記憶體(bytes)
		RuntimeHelper.gc();
		// 原本的記憶體
		long memory = RuntimeHelper.usedMemory();
		// 取得applicationContext
		AcceptorBootstrap.applicationContext = applicationContext;

		// 取得接受器服務
		buildAcceptorService();

		// 啟動
		doStart();
		//
		long endTime = System.currentTimeMillis();
		long durTime = endTime - begTime;
		//
		RuntimeHelper.gc();
		usedMemory = Math.max(usedMemory, (RuntimeHelper.usedMemory() - memory));
		double usedMemoryMB = NumberHelper.round(ByteUnit.BYTE.toMB(usedMemory), 2);
		//
		if (started) {
			String msgPattern = "[{0}] ({1}) ({2}) start in {3} ms, {4} bytes ({5} MB) memory used";
			StringBuilder msg = new StringBuilder(
					MessageFormat.format(msgPattern, id, instanceId, outputId, durTime, usedMemory, usedMemoryMB));
			LOGGER.info(msg.toString());
		} else {
			LOGGER.error("[" + id + "] (" + instanceId + ") (" + outputId + ") started fail");
		}
	} catch (Exception e) {
		started = false;
		LOGGER.error(new StringBuilder("Exception encountered during start()").toString(), e);
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-socklet,代碼行數:49,代碼來源:AcceptorBootstrap.java

示例8: println

import org.openyu.commons.lang.NumberHelper; //導入方法依賴的package包/類
/**
 * PrintlnMemory.
 *
 * @param <T>
 *            the generic type
 * @param title
 *            the title
 * @param value
 *            the value
 */
public static <T> void println(String title, final T value) {
	double bytes = MemoryHelper.sizeOf(value);
	double kb = NumberHelper.round(ByteUnit.BYTE.toKiB(bytes), 1);
	double mb = NumberHelper.round(ByteUnit.BYTE.toMiB(bytes), 1);
	//
	System.out.print(title);
	System.out.println(MessageFormat.format(MEMORY_PATTERN, bytes, kb, mb));
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:19,代碼來源:MemoryHelper.java


注:本文中的org.openyu.commons.lang.NumberHelper.round方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。