本文整理汇总了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);
}
}
示例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()");
}
示例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()");
}