public static void main(String[] args) { SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c=Calendar.getInstance(); System.out.println(sdf.format(c.getTime())); c.add(Calendar.HOUR_OF_DAY, -1);//1小时前抄 System.out.println(sdf.format(c.getTime())); c=Calendar.getInstance(); c.add(Calendar.MINUTE, -1);//1分钟zhidao前 System.out.println(sdf.format(c.getTime())); }。
class MyThread implements Runnable {public void run() {for(int i=0;i<20;i++) {System.out.println(Thread.currentThread().getName()+" "+i);try {Thread.sleep(60000);} catch(InterruptedException e) {return;}}}}public class TestSleep {public static void main(String[] args) {MyThread m = new MyThread();Thread t = new Thread(m,"A");Thread r = new Thread(m,"B");t.start();r.start();}}。
使用多线程吧。是HTTP请求还是Socket请求?
以下仅供参考
package com.kidd.test.zhidao;import java.io.IOException;import java.net.MalformedURLException;import java.net.Socket;import java.net.URL;import java.net.URLConnection;import java.net.UnknownHostException;import com.mashape.unirest.http.Unirest;import com.mashape.unirest.http.exceptions.UnirestException;/** * Hello world! * */public class Main { public static void main(String[] args) {Mainthread mainthread; Thread thread; for (int i = 0; i < 2000; i++) { mainthread = new Mainthread("线程" + i); thread = new Thread(mainthread); thread.start(); } }}class Mainthread implements Runnable { private String name; public Mainthread(String name) { this.name = name; } @Override public void run() { Socket socket = null; try { socket = new Socket("www.baidu.com", 80); System.out.println(name + "连接成功."); } catch (UnknownHostException e) { System.out.println(name + "连接失败."); } catch (IOException e) { System.out.println(name + "连接失败."); } try { if (socket != null && !socket.isClosed()) { socket.close(); } } catch (IOException e) { } }}long startTime=System.currentTimeMillis(); boolen bo=true;while(bo=true){ long endTime=System.currentTimeMillis(); //获取当前毫秒数复 if((endTime-startTime)=60*1000) bo=false; //若超过一分钟则跳出制 /*你要调用的方百法*/ //在这里写度你要调用的方法。
}也可问以用Thread做。
都差不多,我就不写答了。
微信号 LMJX5588
添加微信 享专属策划师1对1定制服务