@SuppressWarnings("resource")
	public static void writer() throws InterruptedException, IOException {
		FileWriter logWriter = new FileWriter(new File(("log" + System.currentTimeMillis() + ".txt")));
	
		MyArrayList cur = null;
		int reopenCnt = 0;
	
		while (true) {
			try {
				if (!graphQueue.isEmpty()) {
					synchronized (graphQueue) {
						cur = graphQueue.poll();
					}
					// System.out.println("===\t try to write " + cur.size()
					// + " record.");
					// followed user
					Long uid1, uid2 = cur.get(0);
					graphWriter.write(uid2 + " followers:\n\n");
	
					int last = 0;
					long t1 = System.currentTimeMillis();
					for (int i = 1; i < cur.size(); i++) {
						uid1 = cur.get(i);
						graphWriter.write(uid1 + "\n");
	
						if ((i % max_batch_size) == 0 || i == cur.size() - 1) {
							graphWriter.flush();
	
							database_cnt += i - last;
							reopenCnt += i - last;
							last = i;
						}
					}
					graphWriter.write("\n");
	
					if (reopenCnt > 10000000) {
						reopenCnt = 0;
						graphWriter.close();
						graphWriter = new FileWriter(new File("./Graph/graph @ " + System.currentTimeMillis() + ".txt"));
					}
	
					finished1Cnt++;
					synchronized (finishedWriter) {
						finishedWriter.write(uid2 + "\n");
						total_finished++;
						finishedWriter.flush();
					}
	
					if (graphQueue.size() == 0 && collected_cnt - database_cnt != 0)
						System.out
								.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n========================\n\n\n\n\n\n\n\n\n\n\n\n");
	
					System.out.println("finish writing " + (cur.size() - 1) + " records in "
							+ (System.currentTimeMillis() - t1) + " millis, waited list " + graphQueue.size()
							+ " user id " + uid2 + " finished1: " + finished1Cnt);
	
					logWriter.write("finish writing " + (cur.size() - 1) + " records in "
							+ (System.currentTimeMillis() - t1) + " millis, waited list " + graphQueue.size()
							+ " user id " + uid2 + " finished1: " + finished1Cnt + "\n");
	
					logWriter.flush();
				} else {
					Thread.sleep(1000);
				}
			} catch (Exception e) {
				e.printStackTrace();
				synchronized (graphQueue) {
					graphQueue.add(cur);
				}
			}
		}
	}