Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

hastable in servlets  RSS feed

 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what is the use of hashTable.put(this,this); in above program
please help
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pretty strange code .. here, hashmap is trying to collect number of threads that are using this Servlet.
best will be run the code yourself and try how this code runs.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is pretty bad code; you should be suspicious about any other code you get from the same source.

The statement you mention does not do what it claims to do (count threads). Given that, it's probably moot to ask what it actually does.

The code has other issues as well, but let's not get started.
 
Arun Dutta
Greenhorn
Posts: 1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
ya by the looks of it, it seems a current instance of the object is pointing to itself in the hashtable, which does not make sense....
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sort of makes sense, but only if you didn't think of using a HashSet instead of a HashMap whose keys and values were identical. Perhaps the author had never heard of HashSet.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply
i am just a learner.
trying to learn from site roseindia.
here is the link of program.
program
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trying to learn from site roseindia.

That explains a lot about the code. RoseIndia is a terrible site, full of bad practices and erronous code. I advise strongly to stay away from it.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!