如何在 Eclipse RCP 应用程序中使用控制台视图
How to use console view in Eclipse RCP Application
我刚开始使用 RCP 编写基于 Java 的应用程序。我正在尝试在我的应用程序中添加一个控制台视图,并将 log4j 的信息输出到控制台。现在可以了。但是有一个问题,它不能像eclipse那样执行每行输出一次,而是在方法完成后输出所有信息。
Object[] elements = tableViewer.getCheckedElements();
if(elements.length > 0){
for(Object ele : elements){
File file = (File) ele;
logger.info("log4j处理目录" + file.getAbsolutePath());
MessageConsoleStream stream = ConsoleFactory.getConsole().newMessageStream();
stream.println("println处理目录" + file.getAbsolutePath());
try {
stream.flush();
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
我尝试使用 stream.println() stream.flush(),但它不起作用。
这是我第一次在 Whosebug 上查询。对不起我的英语。
在用户界面线程中调用 Thread.sleep(1000)
将阻塞整个 UI,什么也不会发生。永远不要这样做。
如果你想每秒做一次某事,请使用 Display
到 运行 代码的 timerExec
方法。
类似于:
Display.getDefault().timerExec(1000, new Runnable() {
@Override
public void run()
{
// TODO output one item to the log
// TODO if need to run again call
Display.getDefault().timerExec(1000, this);
}
});
MessageConsoleStream
的 JavaDoc 说:
Clients should avoid writing large amounts of output to this stream in
the UI thread. The console needs to process the output in the UI
thread and if the client hogs the UI thread writing output to the
console, the console will not be able to process the output.
所以你必须 而不是 循环不断地输出到流而不让 UI 线程中的其他代码 运行.
我刚开始使用 RCP 编写基于 Java 的应用程序。我正在尝试在我的应用程序中添加一个控制台视图,并将 log4j 的信息输出到控制台。现在可以了。但是有一个问题,它不能像eclipse那样执行每行输出一次,而是在方法完成后输出所有信息。
Object[] elements = tableViewer.getCheckedElements();
if(elements.length > 0){
for(Object ele : elements){
File file = (File) ele;
logger.info("log4j处理目录" + file.getAbsolutePath());
MessageConsoleStream stream = ConsoleFactory.getConsole().newMessageStream();
stream.println("println处理目录" + file.getAbsolutePath());
try {
stream.flush();
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
我尝试使用 stream.println() stream.flush(),但它不起作用。 这是我第一次在 Whosebug 上查询。对不起我的英语。
在用户界面线程中调用 Thread.sleep(1000)
将阻塞整个 UI,什么也不会发生。永远不要这样做。
如果你想每秒做一次某事,请使用 Display
到 运行 代码的 timerExec
方法。
类似于:
Display.getDefault().timerExec(1000, new Runnable() {
@Override
public void run()
{
// TODO output one item to the log
// TODO if need to run again call
Display.getDefault().timerExec(1000, this);
}
});
MessageConsoleStream
的 JavaDoc 说:
Clients should avoid writing large amounts of output to this stream in the UI thread. The console needs to process the output in the UI thread and if the client hogs the UI thread writing output to the console, the console will not be able to process the output.
所以你必须 而不是 循环不断地输出到流而不让 UI 线程中的其他代码 运行.