Last active
August 29, 2015 13:57
-
-
Save louiszuckerman/9629461 to your computer and use it in GitHub Desktop.
Uses four threads to read four files and print chars to the console.
This file contains hidden or 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
package com.peircean.glustest; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.net.URISyntaxException; | |
import java.nio.charset.Charset; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
public class Main { | |
public static final String PREFIX = "gluster://localhost:foo/"; | |
public static void main(String[] args) { | |
new Print(PREFIX + "a"); | |
new Print(PREFIX + "b"); | |
new Print(PREFIX + "c"); | |
new Print(PREFIX + "d"); | |
} | |
} | |
class Print extends Thread { | |
String file; | |
public Print(String file) { | |
this.file = file; | |
start(); | |
} | |
@Override | |
public void run() { | |
try { | |
BufferedReader reader = Files.newBufferedReader( | |
Paths.get(new URI(file)), | |
Charset.defaultCharset()); | |
while (reader.ready()) { | |
System.out.print((char) reader.read()); | |
} | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment