public class Task implements Runnable
{
private final String name;
private final int priority;
private final Runnable task;
public Task(String name, int priority, Runnable task)
{
if (null == task) throw new NullPointerException("no task provided");
this.name = name; this.priority = priority; this.task = task;
}
/**
* run() is made final here to prevent any deriving classes
* accidentally ruining the expected behavior
*/
@Override public final void run()
{
final Thread thread = Thread.currentThread();
// cache the current state to restore settings and be polite
final String prevName = thread.getName();
final int prevPriority = thread.getPriority();
// set our thread's config
thread.setName(name);
thread.setPriority(priority);
try { task.run(); } catch (Throwable ignored) {}
// restore previous thread config
thread.setPriority(prevPriority);
thread.setName(prevName);
}
}
我正在使用上面的代码在JavaFX中创建一个表,但是每次在输入新数据后关闭应用程序时,ID的序列编号会提前100,所以如果我输入3条记录并且第一个符号出现在我的序列是100 101 102关闭程序并重新打开并再输入3个记录,序列为200 201 202 存储此值的变量是什么,为什么每次登录都会增加100?或者我该如何解决这个问题? 数据库是DerbyDB,它嵌入了应用程序在C盘上的文件夹中,ID被设置为主键
答案 0 :(得分:1)
@James_Duh
您是如何关闭数据库的? 我知道你可能会错过这行代码
DriverManager.getConnection("jdbc:derby:;shutdown=true")
希望这会有所帮助
@Strawberry很好编辑哪里是答案