Created
December 25, 2014 20:29
-
-
Save maxant/f4308426aa60341e3f57 to your computer and use it in GitHub Desktop.
Trading Engine Servlet, using threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@WebServlet(urlPatterns = { "/sell", "/buy", "/result" }) | |
public class TradingEngineServlet extends HttpServlet { | |
private static final Map<String, TradingEngineThread> kids = new HashMap<>(); | |
static { | |
int chunk = PRODUCT_IDS.length / NUM_KIDS; | |
for (int i = 0, j = PRODUCT_IDS.length; i < j; i += chunk) { | |
String[] temparray = Arrays.copyOfRange(PRODUCT_IDS, i, i + chunk); | |
LOGGER.info("created engine for products " + temparray); | |
TradingEngineThread engineThread = new TradingEngineThread(DELAY, TIMEOUT, (type, data) -> event(type, data)); | |
for (int k = 0; k < temparray.length; k++) { | |
LOGGER.debug("mapping productId '" + temparray[k] + "' to engine " + i); | |
kids.put(temparray[k], engineThread); | |
} | |
LOGGER.info("---started trading"); | |
engineThread.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment