我可以导入,使用其他包中的类吗?在Eclipse中我制作了2个包,一个是主要的,另一个是第二个
main -main (class) second -second (class)
我希望main类的main函数在第二个类中调用函数x.我该怎么做?我试过了:
import second;
second.x(); (if both classes are in the same package then it works)
second.second.x();
Run Code Online (Sandbox Code Playgroud)
但他们都没有工作.我现在不在乎.
我想将我的测试数据库(mysql)中的所有数据复制到我使用hibernate的生产数据库(hsqldb),让它为我创建这些数据库中的表.所以结构/架构是相同的.
使用mysql dump我可以在两个mysql数据库之间复制数据.但在我的情况下,数据库是不同的,我听说mysqldump生成的sql不能与hsqldb一起使用.由于这两种数据库类型都是由jdbc/hibernate支持的,有没有方法/方法/ java库来复制它们之间的数据?
我想在java中编写一个计时器,它将执行以下操作:当程序启动时,启动timer1,它将在45分钟后停止,同时启动第二个计时器,它将在15分钟后停止.此时第一个计时器将再次启动,并重复上述循环,直到程序退出第一个计时器:45分钟(我可以使用计算机的时间)第二个计时器:15分钟(暂停时间)第一个计时器:45分钟(时间)我可以使用电脑)第二个计时器:15分钟(暂停时间)第一个计时器:45分钟(我可以使用计算机的时间)第二个计时器:15分钟(暂停时间)
我不知道如何使用线程和计时器(utils,swing)所以我试图使用while(true)但cpu上升.这是我目前的代码
static int getMinute(){
Calendar cal=Calendar.getInstance();
int minute=cal.getTime().getMinutes();
return minute;
}
public static Runnable clockf(){
if (endTime>=60){
endTime=endTime-60;}
System.out.println(startTime);
System.out.println(currentTime);
System.out.println(endTime);
if(currentTime==endTime){
pauseStart=getMinute();
currentTime=getMinute();
pauseEnd=pauseStart+15;
if(currentTime==pauseEnd){
pauseStart=0;
pauseEnd=0;
startTime=getMinute();
currentTime=getMinute();
endTime=startTime+45;
}
}
else{
update();
}
return null;
Run Code Online (Sandbox Code Playgroud)
}
private static void update() {
currentTime=getMinute();
System.out.println(currentTime);
}
public static void main(String[] args) {
startTime=getMinute();
currentTime=getMinute();
endTime=startTime+45;
Thread t=new Thread(clockf());
t.setDaemon(true);
t.start();
try {
Thread.currentThread().sleep(1000);//60000
} catch (InterruptedException e) {
System.err.println(e);
}
}
Run Code Online (Sandbox Code Playgroud)
但它并不好.有没有办法让clockf方法只运行一次/分钟?或任何其他方式使该计时器运行?