Created
November 25, 2015 10:33
-
-
Save dangnhdev/8e5d490c17db88fe1327 to your computer and use it in GitHub Desktop.
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
import java.util.concurrent.ArrayBlockingQueue; | |
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import org.common.AppLogger; | |
import org.processor.DataFilter; | |
import org.processor.FileReader; | |
import org.processor.FileWriter; | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author 404NotFound | |
*/ | |
public class Main { | |
static final String inputFilePath = "input.txt"; | |
static final String successOutputFile = "success.txt"; | |
static final String failedOutputFile = "failed.txt"; | |
public static void main(String[] args) { | |
AppLogger.getInstance().setLevel(AppLogger.WARM); | |
BlockingQueue<String> dataQueue = new ArrayBlockingQueue<>(1024); | |
BlockingQueue<String> successOutputQueue = new ArrayBlockingQueue<>(1024, true); | |
BlockingQueue<String> failedOutputQueue = new ArrayBlockingQueue<>(1024, true); | |
FileReader reader = new FileReader(inputFilePath, dataQueue); | |
DataFilter checker = new DataFilter(dataQueue, successOutputQueue, failedOutputQueue); | |
FileWriter writeSuccessData = new FileWriter(successOutputFile, successOutputQueue); | |
FileWriter writeFailedData = new FileWriter(failedOutputFile, failedOutputQueue); | |
ExecutorService executor = Executors.newCachedThreadPool(); | |
executor.execute(reader); | |
for (int i = 0; i < 100; i++) { | |
executor.execute(checker); | |
executor.execute(writeSuccessData); | |
executor.execute(writeFailedData); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment