public static void main(String[] args) throws TwitterException, IOException {
		final TwitterStream twitterStream = new TwitterStreamFactory(
				getConfiguration()).getInstance();

		StatusListener listener = new StatusListener() {
			FileOutputStream fout = new FileOutputStream(
					"./Status/status @ "
							+ System.currentTimeMillis() + ".txt");

			ObjectOutputStream oos = new ObjectOutputStream(fout);

			@Override
			public void onStatus(Status status) {
				synchronized (lock) {
					TweetCount++;
				}
				try {
					oos.writeObject(status);
					if (TweetCount % 1000 == 0) {
						oos.flush();
						oos.reset();
					}
					if (TweetCount % 100000 == 0) {
						oos.close();
						fout.close();

						fout = new FileOutputStream(
								"./Status/status @ "
										+ System.currentTimeMillis() + ".txt");
						oos = new ObjectOutputStream(fout);
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onDeletionNotice(
					StatusDeletionNotice statusDeletionNotice) {
			}

			@Override
			public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
				// System.out.println("Got track limitation notice:"
				// + numberOfLimitedStatuses);
			}

			@Override
			public void onScrubGeo(long userId, long upToStatusId) {
				// System.out.println("Got scrub_geo event userId:" + userId
				// + " upToStatusId:" + upToStatusId);
			}

			@Override
			public void onStallWarning(StallWarning warning) {
				// System.out.println("Got stall warning:" + warning);
				// twitterStream.shutdown();
				// twitterStream.sample();
			}

			@Override
			public void onException(Exception ex) {
				// System.out.println("got exception");
				// ex.printStackTrace();
				// twitterStream.shutdown();
				// twitterStream.sample();
			}
		};
		twitterStream.addListener(listener);
		PrintSampleStream print = new PrintSampleStream();

		Thread printerThread = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					printCnt();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		printerThread.start();

		// Either sample or filter can run within the same stream instance
		// print.sample(twitterStream);
		print.filter(twitterStream);
	}