Take the 2-minute tour ×

I am doing multithread processing for generating some products... i will create the products every 10 minutes..i have 2 threads .. first thread will wakeup every 10 minutes... the second thread will generate products... The problem is in second thread...because in second thread ,I will generate some product files(files created by bytes ,all files size will be 30 or 50 mb)..After creating product files,product will be generated by depending on those product files.The product files are created every 10 minutes(it should be created every 10 minutes)..but its taking time more than 10 minutes to create those product files...so can u pls anyone tell me the way to create the files as very fast?

public class Scheduler implements Runnable{
    Thread firstThread;
    public Scheduler() {
        firstThread = new Thread(this,"timer");
    public void run() {

        do {
            if(wakeUptime) {//if wake up 10.00 correct time
            } else {
                // calculate next round of next ten mins...
                // if this process starts at 10.05A.M ,
                // it will sleep 5 mins
                // (round of time in 10 minutes(10minutes - 5 mins))
                // so sleep(5 mins)

        } while(true);


    secondThread(final string time) {
        Runnable r = new Runnable() {
        Thread t = new Thread(r);
        try {
            t.join;//its getting very slow..how to make fast...
        } catch(Exception e) {


    firstFunction(String time) {

        // Here, files will be created every 10 minutes
        // total files size 40 or 50 mb...
        // files created by using bytes.
        // the problem is creating files taking more than 10 minutes...
        // so is there any method to create files very fast?


    secondFunction(String time) {
        // generate product


in the first method,the files will be created..the file size will be 40 or 50 mb...so its taking lot of time to create the files... the files are creating more than 10 minutes...Is there any method to create files as very fast?

share|improve this question
Please format your code you we can read it. And don't put "..." everywhere, it's annoying. –  skaffman Mar 10 '11 at 13:16
I formatted the code, but correcting the english will take me forever, I'll let to OP do it... –  krtek Mar 10 '11 at 13:19
Is there a particular reason why java.util.Timer is no good for your problem? Although, to be honest, I'm not clear on what your question is. –  fd. Mar 10 '11 at 13:25
@Sri: I started to edit your question to get rid of the 3133t sp34k but it's so bad I throwed the towel in... plz stop doin' tat k txh!? –  SyntaxT3rr0r Mar 10 '11 at 14:15
I don't even understand the point of having two threads if the parent is just going to wait for the child to finish. This question is quite confusing. There are lots of issues with the shown code, and the question seems to talk about long-running code that isn't shown. Please clarify the question! –  fd. Mar 10 '11 at 15:29
show 1 more comment

2 Answers

First, i'm recommend to use power production ready sheduler - Quartz from Terracota, he has a trigger system where you can define misfire behavior. Second, of course optimize your code where you create files with productrs - there is no miracles in world, if you cat't create source data for function, you can't run you function with right result

share|improve this answer
add comment

You say "files created by using bytes" - are you writing one byte at a time to the file? Have you wrapped your FileOutputStream in a BufferedOutput stream? Doing so could make an order of magnitude or more improvement.

If you're using Java 5 or higher, you can use a ScheduledExecutor to run the second thread. This will probably be more reliable than reimplementing it on your own.

share|improve this answer
ya..can u give me one small example of ScheduledExecutor ?..i had gone through google..but i dint get idea of tat/... –  Sri Mar 10 '11 at 18:54
add comment

Your Answer


