0

Hello Friends,

I have 6 to 7 threads which are running parallely. Thing is I have to put Thread.Sleep() between each threads. How Can I optimize it?

else if (__selectedString.equals("Master DataInput")) {                                    
                try {

                    if (RecordStore.listRecordStores() != null) {
                        System.out.println("IT FOUND RECORDSTORE ......");

                        RecordStore.deleteRecordStore("Company");
                        RecordStore.deleteRecordStore("Product");
                        RecordStore.deleteRecordStore("Model");
                        RecordStore.deleteRecordStore("Customer");
                        RecordStore.deleteRecordStore("Sales");

                        System.out.println("Delete All RecordStore");



                    } else {
                        System.out.println("IT NOT FOUND RECORD STORE");



                    }

                } catch (Exception e) {
                    e.printStackTrace();


                }


                sync_company scompany = new sync_company(this);
                scompany.sync_start_compnay();





                try {
                    Thread.sleep(2000);


                } catch (Exception e) {
                    e.printStackTrace();


                }


                sync_Product sProduct = new sync_Product(this);
                sProduct.sync_Product();




                try {
                    Thread.sleep(2000);


                } catch (Exception e) {
                    e.printStackTrace();


                }
                sync_Model obj_sync_model = new sync_Model(this);
                obj_sync_model.sync_model_start();



                try {
                    Thread.sleep(2000);


                } catch (Exception e) {
                    e.printStackTrace();


                }

                sync_customer obj_sync_customer = new sync_customer(this);
                obj_sync_customer.sync_customer_start();



                try {
                    Thread.sleep(2000);


                } catch (Exception e) {
                    e.printStackTrace();


                }
                sync_Sales obj_sync_sales = new sync_Sales(this);
                obj_sync_sales.sync_sales_start();



                try {
                    Thread.sleep(2000);
                    alert_master = new Alert("Master DataInput", "DONE SUCESSFULLY", null, AlertType.INFO);
                    alert_master.setTimeout(1000);

                    switchDisplayable(
                            alert_master, Menu_List);


                } catch (Exception e) {
                    e.printStackTrace();


                }


                                     
                // write post-action user code here
            }

Here the thing is we are using Wait Screen of NetBeans. From this window is coming out even though data is importing. we tried Thread.Alive() function for each thread. That was worst case that not working at all. How can I optimize code??

This code is working but thing is its not optimized.

Thank You,
Hakoo Desai.

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Hakoo
0

Please answer the question of this question. This is about Thread concept of Core Java. If anyone not able to understand my question that ask me for clarification.

0

Here, I am repeating my question in possibly simple manner.
I am using WaitScreen(Component of Netbeans visual Midlet) which returns Successful if no exception occurs.

My basic task is to take data from Network and saving them into Record Store.
I put 4 Multiple CheckBox to Import 4 different data table from database.

Now According status of Checkbox I am starting new Thread with passing Runnable Objects.
Now I have to put Thread.Sleep(for Some specific time) between two Start() function. If I don't do that than WaitScreen will come out on pressing the Next button.

Here, I don't want make Thread sleep for specific time. If I do that than below consequences would happen.

If I am making Thread to Sleep for 3 Secs and Data takes 5 Secs then Waitscreen will come for 2 Secs Early.


If I am making Thread to Sleep for 5 Secs and Data takes 3 Secs then Waitscreen will come for 2 Secs Lately.

So, Actually I want, How much time would be taken by Threads, That much time should remain on Screen. And then come back to Menu.

Hope this makes clear.

Thanking You,
Hakoo Desai.

0

I do not have much experiences with threads unfortunately for me, but what you describing doesn't sound right. The WaitScreen should take on responsibility of executing all tasks and till it is done it should show an animation. To help you with thread management you should check this sample of ExecutorService

0

I was experiencing these things from past 5 months. And then I wrote here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.