Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Vaibhav Gargs

Ranch Hand
+ Follow
since Sep 08, 2016
Vaibhav likes ...
Java
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
8
Received in last 30 days
0
Total given
100
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vaibhav Gargs

Thank you Campbell and Paul. I have modified the code to create object but still it doesn't show any difference in memory before and after creating objects:

4 weeks ago
I have written below piece of code to check the memory usage but there is no difference in the memory after creating the objects. Why this is so?


Output is :


254741016
254741016


I am creating multiple objects, so, should it decrease the free memory available? What is the reason for this behaviour?
4 weeks ago
Thank you Stephan. In case, one user sorts based on name, other sorts based on age, and one sorts based on id; then will we sort based on all these different criteria on DB side every time?
1 month ago
Suppose we have an employee database consisting of 10000 records. And, there are REST APIs exposed which return the records in a batch of 500 to the front end and front end will provide the pagination to scroll across those records. Now, if there is a need to implement sorting based on fields individually such as name, id, age etc., then where that sorting will happen - front end or back end? What will be the best design to address this.
1 month ago
Is it safe to say that for same operations, streams will always have better performance compared to collections? Can you please share your experiences regarding this.
2 months ago
A Singleton says that it will have one instance per JVM. In multi nodes cluster environment, we will have multiple instances of application running on those nodes. So, if we have singleton objects in the application, then, won't it break the singleton pattern? Does it mean we should not have any singleton object in multi node clusters?
2 months ago
IF we have a project using 2 external libraries. These 2 libraries will use the same jar file say abc.jar but with different versions 2.0 and 3.0. And, the main project also tries to import some class from these jar files which have different code base in the two versions may be some methods are updated or some logic is implemented differently. So, how the import and jar file version will be resolved in such cases? And, will it be possible to have both versions of jar files on the classpath?
3 months ago
Thanks JJ Roberts.

The executor service won't be calling thread methods internally. I am new to these concepts so may be i am wrong. But I believe the underlying APIs such as thread.start etc. will be called or my understanding is not correct?
In Java 5, executors framework was introduced having the concept of thread pools. We can create fixed size thread pool or cached thread pool etc. Suppose we create a thread pool of 10 threads and all threads are doing their tasks. The thread is started by calling the start method and once we call start method, so again start method can't be called on thread. But in thread pool, the threads go back to the pool after finishing their job and will pick up another task to work upon. So, how does it would be able to call start method again?
Stephan, Campbell, I read on some blogs and websites about the segments. Not on oracle website though. I apologize for not replying earlier.

https://dzone.com/articles/how-concurrenthashmap-works-internally-in-java
https://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html

So, do we have one hashtable or 16 hashtables in concurrenthashmap considering defaults for concurrency control.
4 months ago
@Tim, I am sorry but didn't understand it completely. Can you please explain little with an example.
4 months ago
There are generally defined set of classes - FE -> Controller > Service > DAO -> DB. Here, we autowire service in controller and dao in service layers. And, by default the scope of beans is singleton only.

Suppose 2 users come in and hit the controllers so won't these singleton beans of service or dao create an issue there? How is it handled in real?
4 months ago
Do we have such capabilities to identify message priorities at the broker level? Does it follow JMS specs?
4 months ago
I am trying to think about design principle to be followed in such scenarios. Suppose we hit the DB and fetched the data corresponding to the user, and it returns 10000 rows per user and we have say 1000/10000 users making such requests (all users will have different result sets). Yes, in web-app, we will never show all 10000 results to the user instead it will be utilizing pagination features. So, should we go to the DB again to fetch next page of data or what will be good design principle? If we go to the DB again, won't it perform the sorting operation (10000 total records / 100 results per page  = 100 pages) considering every fetch will get 100 records per fetch. What would be the ideal implementation strategy?
4 months ago
I believe I couldn't make the question clearer, apologize for it. I meant the application needs to connect to the database using some credentials (URL, username, password etc.) and some other connection parameters as well, so, how can we protect this sensitive information in our application.
4 months ago