Lottery end time should not be scheduled in the past.

This commit is contained in:
MobiusDevelopment
2022-10-31 22:24:01 +00:00
parent 259bde1f0f
commit d4e60159b4
6 changed files with 38 additions and 32 deletions

View File

@@ -189,8 +189,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection())
{

View File

@@ -189,8 +189,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection())
{

View File

@@ -67,11 +67,6 @@ public class Lottery
}
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
public int getId()
{
return _number;
@@ -185,8 +180,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_LOTTERY))
@@ -513,6 +509,11 @@ public class Lottery
return res;
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final Lottery INSTANCE = new Lottery();

View File

@@ -67,11 +67,6 @@ public class Lottery
}
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
public int getId()
{
return _number;
@@ -185,8 +180,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_LOTTERY))
@@ -513,6 +509,11 @@ public class Lottery
return res;
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final Lottery INSTANCE = new Lottery();

View File

@@ -67,11 +67,6 @@ public class Lottery
}
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
public int getId()
{
return _number;
@@ -185,8 +180,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_LOTTERY))
@@ -513,6 +509,11 @@ public class Lottery
return res;
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final Lottery INSTANCE = new Lottery();

View File

@@ -67,11 +67,6 @@ public class Lottery
}
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
public int getId()
{
return _number;
@@ -185,8 +180,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis();
}
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE));
ThreadPool.schedule(new finishLottery(), _enddate - System.currentTimeMillis());
final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new stopSellingTickets(), Math.max(endDate - (10 * MINUTE), 0));
ThreadPool.schedule(new finishLottery(), Math.max(endDate, 0));
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_LOTTERY))
@@ -513,6 +509,11 @@ public class Lottery
return res;
}
public static Lottery getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final Lottery INSTANCE = new Lottery();