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(); _enddate = finishtime.getTimeInMillis();
} }
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE)); final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new finishLottery(), _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()) try (Connection con = DatabaseFactory.getConnection())
{ {

View File

@@ -189,8 +189,9 @@ public class Lottery
_enddate = finishtime.getTimeInMillis(); _enddate = finishtime.getTimeInMillis();
} }
ThreadPool.schedule(new stopSellingTickets(), _enddate - System.currentTimeMillis() - (10 * MINUTE)); final long endDate = _enddate - System.currentTimeMillis();
ThreadPool.schedule(new finishLottery(), _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()) try (Connection con = DatabaseFactory.getConnection())
{ {

View File

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