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


Java Logger.entering方法代码示例

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


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

示例1: interceptMethodInvocation

import java.util.logging.Logger; //导入方法依赖的package包/类
@AroundInvoke
public Object interceptMethodInvocation(InvocationContext invocationContext) throws Exception {

    final String methodName = invocationContext.getMethod().getName();
    final String className = invocationContext.getTarget().getClass().getName();

    Logger logger = Logger.getLogger(className);

    final long timeBeforeMethodInvocation;
    final long timeAfterMethodInvocation;
    final long millis;
    logger.entering(className, methodName);
    timeBeforeMethodInvocation = System.currentTimeMillis();

    try {
        return invocationContext.proceed();
    } finally {
        timeAfterMethodInvocation = System.currentTimeMillis();
        millis = timeAfterMethodInvocation - timeBeforeMethodInvocation;
        logger.fine("Method took -> " + millis + " millis to be executed!");
        logger.exiting(className, methodName);
    }
}
 
开发者ID:harperkej,项目名称:store-app-ee,代码行数:24,代码来源:LoggingInterceptor.java

示例2: main

import java.util.logging.Logger; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	
	/*
	 * Get the Logger object
	 */
	Logger logger=MyLoggerFactory.getLogger(Main.class.getName());
	
	/*
	 * Write a message indicating the start of the execution
	 */
	logger.entering(Main.class.getName(), "main()",args);
	
	/*
	 * Create and launch five Task objects
	 */
	Thread threads[]=new Thread[5];
	for (int i=0; i<threads.length; i++) {
		logger.log(Level.INFO,"Launching thread: "+i);
		Task task=new Task();
		threads[i]=new Thread(task);
		logger.log(Level.INFO,"Thread created: "+threads[i].getName());
		threads[i].start();
	}
	
	/*
	 * Write a log message indicating that the threads have been created
	 */
	logger.log(Level.INFO,"Ten Threads created. Waiting for its finalization");
	
	/*
	 * Wait for the finalization of the threads
	 */
	for (int i=0; i<threads.length; i++) {
		try {
			threads[i].join();
			logger.log(Level.INFO,"Thread has finished its execution",threads[i]);
		} catch (InterruptedException e) {
			logger.log(Level.SEVERE, "Exception", e);
		}
	}
	
	/*
	 * Write a log message indicating the end of the program
	 */
	logger.exiting(Main.class.getName(), "main()");
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:50,代码来源:Main.java

示例3: run

import java.util.logging.Logger; //导入方法依赖的package包/类
/**
 * Main method of the task
 */
@Override
public void run() {
	/*
	 * Get the Logger
	 */
	Logger logger=MyLoggerFactory.getLogger(this.getClass().getName());
	
	/*
	 * Write a message indicating the start of the task
	 */
	logger.entering(Thread.currentThread().getName(), "run()");
	
	/*
	 * Sleep the task for two seconds
	 */
	try {
		TimeUnit.SECONDS.sleep(2);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	
	/*
	 * Write a message indicating the end of the task
	 */
	logger.exiting(Thread.currentThread().getName(), "run()");
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:30,代码来源:Task.java


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