Skip to content

Instantly share code, notes, and snippets.

@tobgu
Created May 28, 2012 17:01
Show Gist options
  • Save tobgu/2820093 to your computer and use it in GitHub Desktop.
Save tobgu/2820093 to your computer and use it in GitHub Desktop.
Profiling with visual VM
package primegenerator;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
//import org.springframework.stereotype.Component;
// @Component
public class FileDestination implements IPrimeDestination {
private final String fileName;
private Writer out;
public FileDestination(String fileName) {
this.fileName = fileName;
}
public void initBean() {
out = null;
try {
out = new OutputStreamWriter(
new BufferedOutputStream(new FileOutputStream(fileName, true), 8192));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("Init called");
}
public void destroyBean() {
try {
if(out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Destroy called");
}
@Override
public void put(long prime) {
try {
out.write(Long.toString(prime) + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment