我是 GWT 的新手,我遇到了一个大问题。我有一个 gwt/extjs gwt2.2.0 应用程序。我需要建立一个图表,显示每秒传入消息数量的实时信息。系统监视器之类的东西。我发现的唯一方法是添加从服务器调用 messageQueueSize 的代码,并将其添加到区域图中,使用 timer.shedule(1000) 将其添加到计时器块中,并将所有这些添加到
$while(true)
堵塞。当我尝试运行我的应用程序时,我的应用程序正在循环(因为 While 占用了所有线程)。请帮我解决这个问题或找到实现这部分应用程序的想法。这是我正在尝试做的代码:
$ public class ExampleChart extends ContentPanel{
ArrayList<String> timeList = new ArrayList<String>();
ArrayList<Long> queueSize = new ArrayList<Long>();
private final ServerManagementAsync serverManagementSvc = GWT.create(ServerManagement.class);
public ContentPanel createChart(final String customerId, boolean warrant){
setHeading("Messages by domain");
setFrame(true);
setSize(550, 400);
setLayout(new FitLayout());
String url = "/gxt/chart/open-flash-chart.swf";
final Chart chart = new Chart(url);
chart.setBorders(true);
timeList = getTimeList(timeList);
while (warrant){
Timer t = new Timer(){
public void run(){
ExampleChart ec = new ExampleChart();
AsyncCallback<Long> ac = new AsyncCallback<Long>() {
@Override
public void onFailure(Throwable throwable) {
}
@Override
public void onSuccess(Long integer) {
timeList = getTimeList(timeList);
if (queueSize.size()<11){
queueSize.add(integer);
} else{
for (int i = 0; i<queueSize.size()-1; i++){
queueSize.set(i,queueSize.get(i+1));
}
}
chart.setChartModel(getAreaChart(timeList, queueSize));
add(chart);
repaint();
}
};
serverManagementSvc.getMessageQueueSize(customerId, ac);
}
};
t.schedule(2000);
}
chart.setChartModel(getAreaChart(timeList, queueSize));
add(chart);
repaint();
return this;
}
public ArrayList<String> getTimeList(ArrayList<String> TimeList){
ArrayList<String> timeList = TimeList;
if (timeList.size() < 11){
timeList.add(getCurrentTime());
} else {
for (int i = 0; i<timeList.size()-1; i++){
timeList.set(i, timeList.get(i+1));
}
timeList.set(10, getCurrentTime());
}
return timeList;
}
public String getCurrentTime(){
Date date = new Date();
String hrs = Integer.toString(date.getHours());
String min = Integer.toString(date.getMinutes());
String sec = Integer.toString(date.getSeconds());
return hrs + ":" + min + ":" + sec;
}
public ChartModel getAreaChart(ArrayList<String> dateList, ArrayList<Long> queueSize)
{
ChartModel cm = new ChartModel("Messages per domain", "font-size: 14px; font-family: Verdana;");
cm.setBackgroundColour("#ffffff");
XAxis xa = new XAxis();
xa.setLabels(dateList);
cm.setXAxis(xa);
AreaChart area1 = new AreaChart();
area1.setFillAlpha(0.3f);
area1.setColour("#ff0000");
area1.setFillColour("#ff0000");
for (int n = 0; n<queueSize.size(); n++){
area1.addValues(queueSize.get(n));
}
cm.addChartConfig(area1);
return cm;
}
}