Reputation: 1287
i have a database. imagine that my database have 1.000.000.000 records or includes 100 gb datas. i want to write a program.
the program basically will send a query to database to take 10 records and will display this records on the screen. then the user will use scroll bar on the mause to change the records displayed. for example when user scrolled down program will display records between 2 and 11. if the user keep scrolling down, the records keep displaying like between 3 and 12, 4 and 13 ... also the user can scroll up.
how can i use threads in a program like that. can anyone give a general idea for it. also if i want to use a pattern, which pattern can i use and why?
note: i can also use two buttons (for up and down) instead of scroll bar.
Upvotes: 0
Views: 362
Reputation: 1954
See allso for Model View Controller (MVC), Model View Presenter (MVP) and Model View ViewModel (MVVM) patterns to seperate the visualisation, business logic and data layers.
Upvotes: 0
Reputation: 9672
A typical pattern would be to have one thread handle the UI. Mouse, windowing, drawing, etc.
A worker thread would be created that did the actual DB i/o. That thread would collect responses from the database & place them in a buffer (or send them piecemeal) to the UI thread, which would then display them as they came in. Alternately, you could have the UI thread query the worker for a given range of records as the user works with the UI and this would require a way for the worker to respond immediately even if it didn't have all of the needed data.
At any rate, keeping the UI responsive while the work is executed is a typical pattern.
At the DB level itself, there are many ways to break down the execution of the search within the records into multiple parallel tasks (running on independent threads or fibers) doing the actual search requested from your program.
Upvotes: 1