• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can you stop a method request by recalling the method?  RSS feed

 
Leigh Taylor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create an auto complete style of functionality where by each key stroke from the user calls a database request to display matches on the fly.

Obviously the amount of matches returned and the time taken for data conversions is quicker the more characters that have been submitted. Which leads me to my problem.

On a key stroke we fire a getMatchesAndConvertToObjects method(pretend this method goes through the architecture layers, retrieves data, and then converts them to objects).

So lets say the user input string is 'smi', the method is called, whilst the method is doing it's thing the user has inputted another character making the string 'smit', once again the method is called.

My problem is that in some cases the 'smit' request catches the 'smi' request and may even overtake it. This causes lots of problems.

Is there a way to stop the initial request? Or is there a workaround to protect myself from having this happen?

Thanks,

Leigh

[ March 05, 2008: Message edited by: Leigh Taylor ]
[ March 05, 2008: Message edited by: Leigh Taylor ]
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think that the approach of going to database on every keystroke is a wastage of resources and inefficient coding.

Suppose, a user enters "smit" and till the time you got the result he deleted the word and reenterd "abcd". Does it really make sense to then again get into a process to bring data.

I suugest that initially you get all the existing names from database and dump them in some hidden variable on the poge itself. Now, you can use a javascript comparator to get the relevant result by comparing user keystroked value and the list of values in hidden variable.

This in turn will be faster as it is on client side and moreover and most importantly conserve resource utilisation.
 
Leigh Taylor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response. I probably should have added more detail but didn't want to clutter my question too much.

In the case i provided i am retrieving address records. The database contains almost 10 million rows of data. So this is why i've had to retrieve data instead populating an entire table. My keystroke method only kicks in on the 3rd character which substantially helps performance. We are talking about .5 of a second between entering a key, getting the data from the database, converting them to my objects, then displaying the information within a listbox.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well as far as I understand if you are in a thredsafe environment and you submit multiple requests of same type on after another then the output will be sequential.

What I mean is if you went to get results for "smi" and in the meantime user entered "smit" then the response of both requests should come in order. I don't think there has to be a problem with that.

Well, I am digressing from the post but, a suggestion is that you should use AJAX for better user interface.
 
Leigh Taylor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks anyway.

Though i am asking this question because i do not have the answer and am asking people with far more knowledge than me for help, if anyone has a better way to approach this then i am more than happy to listen. This functionality is not something i have thought up, but instead was part of the old system i am redeveloping.

In a few cases i have seen the method calls overtake each other, hence my concern. I.E, the list for 'smit' populates only to be followed by the populating of the 'smi' list.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though i am asking this question because i do not have the answer and am asking people with far more knowledge than me for help, if anyone has a better way to approach this then i am more than happy to listen. This functionality is not something i have thought up, but instead was part of the old system i am redeveloping.


Everybody asks only if he doesn't have a way out. I don't know what makes you say that. As in your case as I see that delaing with millions of records is the problem. If you have to go ahead with this "old" functionality then probably what you are doing is OK. Or, you can increase the request submit threshold to 5words than 3words (or something like thet) to increase efficieny. If there are some constraints that particular addresses go with particular conditions, then you can use indexing in database to get the results faster and interacting with only those records that are required.

In a few cases i have seen the method calls overtake each other, hence my concern. I.E, the list for 'smit' populates only to be followed by the populating of the 'smi' list.


That's what I said that if you are in a threadsafe environment then the "smit" response will be followed only after "smi" response is completed. What I mean is the last request will reflect last.
[ March 05, 2008: Message edited by: Anubhav Anand ]
 
Leigh Taylor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though i am asking this question because i do not have the answer and am asking people with far more knowledge than me for help, if anyone has a better way to approach this then i am more than happy to listen. This functionality is not something i have thought up, but instead was part of the old system i am redeveloping.


I only said that because i felt you were annoyed with me and were leaving the post. Just letting you know that i am open to suggestions.

Currently performance does not seem to be an issue which is great news. The worst case scenario takes about 2 seconds. Though i do not know how to achieve this thread safe environment you speak of.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only said that because i felt you were annoyed with me and were leaving the post. Just letting you know that i am open to suggestions.


Well we are here to help each other so nothing like getting annoyed.

Well, I am digressing from the post but, a suggestion is that you should use AJAX for better user interface.


This was not like that I was leaving the post but a suggestion that will improve the quality of your application.

Currently performance does not seem to be an issue which is great news. The worst case scenario takes about 2 seconds. Though i do not know how to achieve this thread safe environment you speak of.


Knowing that performance is not an issue right now is pretty soothing, but, the hard thing to know is that you never know when the performance problem pops up.
By threadsafe I mean code that will work fine even if many Threads are executing it simultaneously. You can refer this.

Although, mostly the frameworks provide this feature by default e.g Struts is threadsafe.
Another example is StringBuffer is threadsafe while StringBuilder(JDK 5.0) is not.
 
Leigh Taylor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. An interesting read and definitely helped me understand threading a lot more. Which essentially is what i needed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!