• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please tell me whether this procedure is correct or not.

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, please tell me whether the following code is right or wrong.

I suppressed the warnings because actually this code is a part of my web application where many requests come to a servlet and there will me a Validator class to validate the data. So I cant make the Pattern and Matcher classes static.

Is this procedure correct. Thank you all in advance.
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:Hi everybody, please tell me whether the following code is right or wrong.


Does it work? Does it do what you'd expect?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:Yes

Then I would go ahead and say it's correct.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kevin.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:
I suppressed the warnings because actually this code is a part of my web application where many requests come to a servlet and there will me a Validator class to validate the data. So I cant make the Pattern and Matcher classes static.

That's nonsense. pattern.compile(roll) is exactly the same as the static call Pattern.compile(roll).

I'd even change the entire class to make pattern and matcher local variables. Their value only matters during the methods, and they are reset each time.

How I'd implement them:
You can also use two static final Patterns, but I'm not sure how thread safe these will then be.

By the way, I think you want to make "05n61a0564" and "r09" parameters to these methods
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob.
Rob Prime wrote:By the way, I think you want to make "05n61a0564" and "r09" parameters to these methods

Yes I want to make those as parameters to those methods. But this is a web application. Will it work fine, because many requests will be coming. Will this program deliver good performance? I am sorry if you think I am asking an unrelated question in Java forum.

Thank you.
 
Paul Clapham
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:Will it work fine, because many requests will be coming. Will this program deliver good performance?


But wait a minute. You were asked earlier if it did what you would expect. And you said "Yes". But now it turns out you don't actually know whether it does what you would expect.

However it doesn't really matter because you haven't really described what you would expect anyway. "Good performance"? That really isn't very specific. Are you going to have a web request which does this and nothing else at all? And how long would it have to take before you considered it "not good performance"? You probably don't have an answer for that, because you haven't really thought about it much. But even if you did have a specific performance requirement, nobody could tell by just looking at the code how it would perform. That would depend on the speed of the processor and the size of the memory allocated to the web application server and the number of processors in the machine and the other processes running on the machine and the speed of the network connecting the users to the machine... by now you should get what I'm saying: "It depends. It's more complicated than that."

So the way to go, if this were a real piece of code, would be to decide to use it. Quite likely it wouldn't make any difference if it could be tweaked to run in 1/100 of the time, as it's only going to be a tiny fraction of the whole processing for the request. And remember what my brother Don Knuth said: "Premature optimization is the root of all evil." And that's what you are doing with that question.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul, I am having a requirement in my web application where a user uploads a excel file containing a list of students. I have to validate those and insert it into database, so for validation purpose I wrote this code. You can refer this forum for the actual problem I am facing.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
But wait a minute. You were asked earlier if it did what you would expect. And you said "Yes". But now it turns out you don't actually know whether it does what you would expect.
Previously I was not talking about the performance, I was simply talking about whether can I use static content from a non static context.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic