// Verify: do stress test, by opening IndexReaders and // IndexWriters over & over in 2 threads and making sure // no unexpected exceptions are raised: public void testStressLocks() throws Exception { Path tempPath = createTempDir(); assumeFalse("cannot handle buggy Files.delete", TestUtil.hasWindowsFS(tempPath)); Directory dir = getDirectory(tempPath); // First create a 1 doc index: IndexWriter w = new IndexWriter( dir, new IndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.CREATE)); addDoc(w); w.close(); WriterThread writer = new WriterThread(100, dir); SearcherThread searcher = new SearcherThread(100, dir); writer.start(); searcher.start(); while (writer.isAlive() || searcher.isAlive()) { Thread.sleep(1000); } assertTrue("IndexWriter hit unexpected exceptions", !writer.hitException); assertTrue("IndexSearcher hit unexpected exceptions", !searcher.hitException); dir.close(); }
private Logger() { CharSequence time = DateFormat.format("yyyy-MM-dd", System.currentTimeMillis()); File logDir = new File(FILE_PATH); if (!logDir.exists()) { logDir.mkdirs(); } Log.e(TAG, "" + logDir.exists()); nLogFile = new File(logDir, time + ".txt"); nWaitLogs = new ArrayBlockingQueue<String>(QUEUE_SIZE, true); nLogThread = new WriterThread(nWaitLogs); nLogThread.start(); }
/** * Construct a new ParallelTextWriter wrapper. * * @param name the name of the thread. * @param autoFlush indicates if the underlying writer should be flushed after the queue is * flushed. * @param writer a character stream used for output. */ public ParallelTextWriter(String name, boolean autoFlush, TextWriter writer) { this.name = name; this.autoFlush = autoFlush; this.writer = writer; this.queue = new ConcurrentLinkedQueue<String>(); this.writerThread = null; this.stopRequested = new AtomicBoolean(false); writerThread = new WriterThread(); writerThread.start(); DirectoryServer.registerShutdownListener(this); }