锘??xml version="1.0" encoding="utf-8" standalone="yes"?> In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well. In the long run, the frequency of execution will generally be slightly lower than the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-delay execution is appropriate for recurring activities that require "smoothness." In other words, it is appropriate for activities where it is more important to keep the frequency accurate in the short run than in the long run. This includes most animation tasks, such as blinking a cursor at regular intervals. It also includes tasks wherein regular activity is performed in response to human input, such as automatically repeating a character as long as a key is held down.
In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well. In the long run, the frequency of execution will generally be slightly lower than the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-delay execution is appropriate for recurring activities that require "smoothness." In other words, it is appropriate for activities where it is more important to keep the frequency accurate in the short run than in the long run. This includes most animation tasks, such as blinking a cursor at regular intervals. It also includes tasks wherein regular activity is performed in response to human input, such as automatically repeating a character as long as a key is held down.
In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up." In the long run, the frequency of execution will be exactly the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.
In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up." In the long run, the frequency of execution will be exactly the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.
Rectangle聽rect聽=聽comp.getBounds();
聽BufferedImage聽bufImage聽=聽new聽BufferedImage(rect.width,
聽聽聽聽聽聽聽聽聽聽聽rect.height,
聽聽聽聽聽聽聽聽聽聽聽BufferedImage.TYPE_INT_RGB);
聽Graphics聽g聽=聽bufImage.getGraphics();
聽g.translate(-rect.x,聽-rect.y);
聽comp.paint(g);
榪欐牱錛孞Component涓殑鍥懼儚灝變繚瀛樺埌BufferedImage涓簡銆?br />鍘熸枃鐨勯摼鎺ワ細http://dev.csdn.net/article/13/13531.shtm
]]>
]]>
]]>
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.awt.*, java.text.*, java.util.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.*" %>
<%@ page import="org.jfree.chart.servlet.ServletUtilities" %>
<%@ page import="org.jfree.data.DefaultCategoryDataset" %>
<%@ page import="org.jfree.ui.TextAnchor" %>
<%
//The data for the bar chart
double[] data =
{85, 156, 179.5, 211, 123};
//The labels for the bar chart
String[] labels =
{"Mon", "Tue", "Wed", "Thu", "Fri"};
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < data.length; i++)
{
dataset.addValue(data[i], null, labels[i]);
}
JFreeChart chart = ChartFactory.createBarChart3D("Weekly Server Load", "Work Week 25", "MBytes", dataset, PlotOrientation.VERTICAL, false, false, false);
chart.setBackgroundPaint(new Color(0xE1E1E1));
CategoryPlot plot = chart.getCategoryPlot();
// 璁劇疆Y杞存樉紺烘暣鏁?/SPAN>
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryAxis domainAxis = plot.getDomainAxis();
//璁劇疆璺濈鍥劇墖宸︾璺濈
domainAxis.setLowerMargin(0.05);
BarRenderer3D renderer = new BarRenderer3D();
//璁劇疆鏌辯殑棰滆壊
renderer.setSeriesPaint(0, new Color(0xff00));
plot.setRenderer(renderer);
String filename = ServletUtilities.saveChartAsPNG(chart, 300, 280, null, session);
String graphURL = request.getContextPath() + "/displayChart?filename=" + filename;
%>
<html>
<body topmargin="5" leftmargin="5" rightmargin="0">
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
3D Bar Chart
</div>
<br>
<img src="<%= graphURL %>" border=0>
</body>
</html>
鐢誨嚭鏉ョ殑鍥撅細
鍜孋hartDirector鐢誨嚭鏉ョ殑鍥懼仛涓涓瘮杈冿細
]]>
鑼冧緥紼嬪簭錛?BR>
<%@page import="ChartDirector.*" %>
<%
//The data for the bar chart
double[] data =
{85, 156, 179.5, 211, 123};
//The labels for the bar chart
String[] labels =
{"Mon", "Tue", "Wed", "Thu", "Fri"};
//Create a XYChart object of size 300 x 280 pixels
XYChart c = new XYChart(300, 280);
//Set the plotarea at (45, 30) and of size 200 x 200 pixels
c.setPlotArea(45, 30, 200, 200);
//Add a title to the chart
c.addTitle("Weekly Server Load");
//Add a title to the y axis
c.yAxis().setTitle("MBytes");
//Add a title to the x axis
c.xAxis().setTitle("Work Week 25");
//Add a bar chart layer with green (0x00ff00) bars using the given data
c.addBarLayer(data, 0xff00).set3D();
//Set the labels on the x axis.
c.xAxis().setLabels(labels);
//output the chart
String chart1URL = c.makeSession(request, "chart1");
//include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: {value} MBytes'")
;
%>
<html>
<body topmargin="5" leftmargin="5" rightmargin="0">
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
3D Bar Chart
</div>
<hr color="#000080">
<a href="viewsource.jsp?file=<%=request.getServletPath()%>">
<font size="2" face="Verdana">View Chart Source Code</font>
</a>
</div>
<br>
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>
</body>
</html>
濡傛灉瑕佸湪鏌辯殑欏墮儴鏄劇ず鏁板鹼紝鍙互璋冪敤Layer鐨剆etDataLabelFormat鏂規硶璁劇疆錛岃寖渚嬶細layer.setDataLabelFormat("{value}");
鍏跺畠鐨勪緥瀛愬彲浠ュ弬鑰冨畠鐨勬枃妗g殑璇存槑銆侰hartDirector鐨勭綉鍧錛?A >http://www.advsofteng.com
]]>
class Worker extends TimerTask
{
public void run()
{
System.out.println("鎴戝湪宸ヤ綔鍟︼紒");
}
}
Timer綾葷敤schedule鏂規硶鎴栬卻cheduleAtFixedRate鏂規硶鍚姩瀹氭椂鎵ц錛宻chedule閲嶈澆浜嗗洓涓増鏈紝scheduleAtFixedRate閲嶈澆浜嗕袱涓傛瘡涓柟娉曠殑瀹炵幇閮戒笉鍚岋紝涓嬮潰鏄瘡涓柟娉曠殑璇存槑錛?BR>
schedule
public void schedule(TimerTask task,
long delay)
璇存槑錛氳鏂規硶浼氬湪璁懼畾鐨勫歡鏃跺悗鎵ц涓嬈′換鍔°?BR>
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
IllegalArgumentException
- if delay is negative, or delay + System.currentTimeMillis() is negative.
IllegalStateException
- if task was already scheduled or cancelled, or timer was cancelled.
schedule
public void schedule(TimerTask task,
Date time)
璇存槑錛氳鏂規硶浼氬湪鎸囧畾鐨勬椂闂寸偣鎵ц涓嬈′換鍔°?BR>
task
- task to be scheduled.
time
- time at which task is to be executed.
IllegalArgumentException
- if time.getTime() is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
schedule
public void schedule(TimerTask task,
long delay,
long period)
璇存槑錛氳鏂規硶浼氬湪鎸囧畾鐨勫歡鏃跺悗鎵ц浠誨姟錛屽茍涓斿湪璁懼畾鐨勫懆鏈熷畾鏃舵墽琛屼換鍔°?BR>
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if delay is negative, or delay + System.currentTimeMillis() is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
schedule
public void schedule(TimerTask task,
Date firstTime,
long period)
璇存槑錛氳鏂規硶浼氬湪鎸囧畾鐨勬椂闂寸偣鎵ц浠誨姟錛岀劧鍚庝粠璇ユ椂闂寸偣寮濮嬶紝鍦ㄨ瀹氱殑鍛ㄦ湡瀹氭椂鎵ц浠誨姟銆傜壒鍒殑錛屽鏋滆瀹氱殑鏃墮棿鐐瑰湪褰撳墠鏃墮棿涔嬪墠錛屼換鍔′細琚┈涓婃墽琛岋紝鐒跺悗寮濮嬫寜鐓ц瀹氱殑鍛ㄦ湡瀹氭椂鎵ц浠誨姟銆?BR>
task
- task to be scheduled.
firstTime
- First time at which task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if time.getTime() is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
scheduleAtFixedRate
public void scheduleAtFixedRate(TimerTask task,
long delay,
long period)
璇存槑錛氳鏂規硶鍜宻chedule鐨勭浉鍚屽弬鏁扮殑鐗堟湰綾諱技錛屼笉鍚岀殑鏄紝濡傛灉璇ヤ換鍔″洜涓烘煇浜涘師鍥狅紙渚嬪鍨冨溇鏀墮泦錛夎屽歡榪熸墽琛岋紝閭d箞鎺ヤ笅鏉ョ殑浠誨姟浼氬敖鍙兘鐨勫揩閫熸墽琛岋紝浠ヨ刀涓婄壒瀹氱殑鏃墮棿鐐廣?BR>
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if delay is negative, or delay + System.currentTimeMillis() is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
scheduleAtFixedRate
public void scheduleAtFixedRate(TimerTask task,
Date firstTime,
long period)
璇存槑錛氬拰涓婁竴涓柟娉曠被浼箋?BR>
task
- task to be scheduled.
firstTime
- First time at which task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if time.getTime() is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
涓嬮潰鏄垜鐨勪竴涓祴璇曠墖鏂細
public static void main(String[] args) throws Exception
{
Timer timer = new Timer(false);
timer.schedule(new Worker(), new Date(System.currentTimeMillis() + 1000));
}
]]>
]]>
Object obj1 = "abc";
Object obj2 = "cde";
if ((obj1 == null && obj2 == null) || (obj1 != null && obj1.equals(obj2))
|| (obj2 != null && obj2.equals(obj1)))
{
System.out.println("equals");
}
榪欐牱鐨勭▼搴忥紝璇昏搗鏉ョ湡鏄尯鎷楀彛銆傛垜涓鐩存病鏈夋兂鍒頒粈涔堝ソ鐨勬柟娉曡В鍐寵繖涓棶棰橈紝鐩村埌浠婂ぉ鍦ㄧ湅鍒癑DK鐨凙bstractList婧愮爜鐨別quals鏂規硶鐨勫疄鐜版椂錛岀湅鍒拌繖涓孌碉細
if (!(o1==null ? o2==null : o1.equals(o2)))
return false;
鍘熸潵鐢ㄤ笁鍏冭繍綆楃鍙互寰堝ソ鐨勮В鍐寵繖涓棶棰橈紝鍛靛懙錛屾垜鍓嶉潰鐨勭▼搴忓彲浠ユ敼鍐欐垚錛?BR>
Object obj1 = "abc";
Object obj2 = "cde";
if (obj1 == null ? obj2 == null : obj1.equals(obj2))
System.out.println("equals");
鐪熸槸綆媧佸浜嗭紒
]]>
2.鍦ㄤ嬌鐢ㄩ潪闃誨IO鏃訛紝闇瑕佹妸璇hannel璁劇疆鎴愰潪闃誨鐨勶紝鍗抽渶瑕佽皟鐢⊿ocketChannel.configureBlocking(false);
3.濡傛灉璇hannel娉ㄥ唽浜唖elector錛岄偅涔堝湪榪斿洖璇ュ疄渚嬪埌瀵硅薄姹犱腑錛岄渶瑕佹妸娉ㄥ唽鐨剆elector娓呴櫎錛屽嵆闇瑕佽皟鐢⊿elector鐨刢lose鏂規硶銆?BR>
涓嬮潰鏄竴孌靛簲鐢ㄥ満鏅殑渚嬪瓙錛?BR>
// 鎶婂懡浠よ緭鍑?/SPAN>
channel.configureBlocking(true);
PrintWriter writer = new PrintWriter(channel.socket().getOutputStream(), false);
writer.write(command.endsWith("\n") ? command : command + "\n");
writer.flush();
channel.configureBlocking(false);
// 鍒涘緩Selector
Selector selector = Selector.open();
// 鍚慡elector娉ㄥ唽鎴戜滑闇瑕佺殑READ浜嬩歡
SelectionKey skey = channel.register(selector, SelectionKey.OP_READ);
boolean stop = false;
int n = 0;
int read = 0;
ByteBuffer buffer = ByteBuffer.allocate(1024);
// 杞
while (!stop)
{
// 鑾峰彇Selector榪斿洖鐨勬椂闂村?/SPAN>
n = selector.select();
// 褰撲紶鍥炵殑鍊煎ぇ浜?浜嬶紝璇諱簨浠跺彂鐢熶簡
if (n > 0)
{
// 澶勭悊鍙戠敓鐨勪簨浠?/SPAN>
}
}
selector.close();
]]>
package sample.proxy;
/**//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/
public interface TestInterface
{
public String print();
}
package sample.proxy;
/**//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/
public class TestImpl implements TestInterface
{
public String print()
{
return "Hello, it's from TestImpl class";
}
}
涓嬮潰鎷︽埅print鏂規硶錛岃皟鐢ㄨ嚜宸辯殑瀹炵幇錛岃繖闇瑕佸疄鐜癹ava.lang.reflect.InvocationHandler鎺ュ彛銆?BR>
package sample.proxy;
import java.lang.reflect.*;
/**//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/
public class TestHandler implements InvocationHandler
{
TestInterface test;
/**//**
* 灝嗗姩鎬佷唬鐞嗙粦瀹氬埌鎸囧畾鐨凾estInterface
* @param test TestInterface
* @return TestInterface 緇戝畾浠g悊鍚庣殑TestInterface
*/
public TestInterface bind(TestInterface test)
{
this.test = test;
TestInterface proxyTest = (TestInterface) Proxy.newProxyInstance(
test.getClass().getClassLoader(), test.getClass().getInterfaces(), this);
return proxyTest;
}
/**//**
* 鏂規硶璋冪敤鎷︽埅鍣紝鎷︽埅print鏂規硶
* @param proxy Object
* @param method Method
* @param args Object[]
* @return Object
* @throws Throwable
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
// 濡傛灉璋冪敤鐨勬槸print鏂規硶錛屽垯鏇挎崲鎺?/SPAN>
if ("print".equals(method.getName()))
{
return "HaHa, It's come from TestHandler";
} else
{
return method.invoke(this.test, args);
}
}
}
涓嬮潰鏄祴璇曠敤渚嬶細
package sample.test;
import junit.framework.*;
import sample.proxy.*;
/**//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/
public class TestDynamicProxy extends TestCase
{
private TestInterface test = null;
protected void setUp() throws Exception
{
super.setUp();
TestHandler handler = new TestHandler();
// 鐢╤andler鍘葷敓鎴愬疄渚?/SPAN>
test = handler.bind(new TestImpl());
}
protected void tearDown() throws Exception
{
test = null;
super.tearDown();
}
public void testPrint()
{
System.out.println(test.print());
}
}
榪愯嫻嬭瘯鐢ㄤ緥錛屽彲浠ョ湅鍒拌緭鍑虹殑鏄淗aHa, It's come from TestHandler鈥濄?img src ="http://www.tkk7.com/georgehill/aggbug/5126.html" width = "1" height = "1" />
]]>
]]>
package sample.nio;
import java.io.*;
import java.net.*;
import java.nio.channels.*;
import java.util.*;
/**//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/
public class Server
{
private int port;
public Server(int port)
{
this.port = port;
}
public void startServer() throws IOException
{
// 鍒涘緩ServerSocketChannel騫朵笖緇戝畾鍒版寚瀹氱殑绔彛
ServerSocketChannel ssc = ServerSocketChannel.open();
InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), port);
ssc.socket().bind(address);
ssc.configureBlocking(false);
// 鍒涘緩Selector錛屽茍涓旀敞鍐孉CCEPT浜嬩歡
Selector selector = Selector.open();
SelectionKey skey = ssc.register(selector, SelectionKey.OP_ACCEPT);
boolean stop = false;
int n = 0;
System.out.println("Server Start");
// 杞
while (!stop)
{
// 鑾峰彇Selector榪斿洖鐨勬椂闂村?/SPAN>
n = selector.select();
// 褰撲紶鍥炵殑鍊煎ぇ浜?浜嬶紝璇繪椂闂村彂鐢熶簡
if (n > 0)
{
Set set = selector.selectedKeys();
Iterator it = set.iterator();
while (it.hasNext())
{
skey = (SelectionKey) it.next();
it.remove();
if (skey.isAcceptable())
{
// 浠巆hannel()涓彇寰楀垰鍒氭敞鍐岀殑Channel
Socket socket = ((ServerSocketChannel) skey.channel()).accept().socket();
PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
// 灝?Hello, World"鍐欏叆
writer.write("Hello, World!\n");
// 鐫$湢3縐?/SPAN>
try
{
Thread.sleep(3000);
} catch (InterruptedException ie)
{
}
// 灝?EXIT"鍐欏叆Buffer
writer.write("EXIT");
// 閫鍑虹▼搴?/SPAN>
writer.close();
// stop = true;
}
}
}
}
ssc.close();
System.out.println("Server Stop");
}
public static void main(String[] args) throws Exception
{
Server server = new Server(5000);
server.startServer();
}
}
]]>
]]>
鍦?.0涓殑server.xml鏂囦歡鏍煎紡濡備笅錛?/P>