Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Siddhant Agarwal

+ Follow
since Jun 26, 2017
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Siddhant Agarwal

We have a web services platform where we deploy Java based web services inside docker containers. By default, up until now we were making a Max Metaspace allocation of 256MB. However, we found that for most of the 95% of the services the maximum used metaspace never crosses 150MB. To add to that we have over 5000 instance of services running which is only increasing as more and more teams move from legacy system to this.

The way the platform works is like this:
We have a customized runtime which runs on top of Dropwizard. We take the WAR, read its contents and pass onto the underlying Jetty web server which is embedded in Dropwizard. This allows us to maintain and improve the runtime independent of the WAR which is developed by the consumer teams. We also have a monitoring system in place which monitor all the JVM metrics and reports it.

Optimization 1st Attempt
We used the monitoring system to identify the max used metaspace for each and every service. On top of that we added some buffer and set that as the max metaspace for the services in our internal environments. However, we quickly realized that wasn't working partially when we started receiving alerts for some of the services (~5-6%). This where we started investigating further. We found that for some of the service, the WAR version didn't change, but there was a change in the runtime version, which may have contributed to increase in the required metaspace for those services and this is where we need help.

We have two completely different components which are developed independently but one relies on other for it to run. So, how do we even estimate the required metaspace upfront so that we can dynamically set the required metaspace during deployment for our services.
1 week ago
I am just beginning to work on a  JAVA based project under which I have an option to use either a JDBC based transaction or the Java Transaction API? Now, I am not much aware of both of them, but I went through few posts online. However, I couldn't really understand when to use which one? How do we differentiate what would suit our need under which scenario?
ohh. So, it has to be a difference in the list or type of parameters for overloading to be valid. For a change in modifier, access specifier, return type or anything else in the method signature won't make a difference.
Thanks for the clarification!

Sorry for the late reply.
3 years ago
I declared two functions in a class like this:

Case 1:
Only Type A and Type B are defined in my class
a. It compile successfully.

b. When I call function like this: or It calls the Type B implementation.

c. When I call function like this: It shows me a compile time error.

Case 2:
All three types are defined in my class -> I get a compile time error saying that func2 is already defined.

Firstly, why is this difference in behavior observed between Case 1 and Case 2? When we had two functions(Type A and Type B) where the only difference was the return type, it compiled. However, when we added Type 3, again with a different return type, it didn't compile?

Secondly, between Case1.b and Case1.c, on what basis does Java decide when to call which implementation of the function (between Type A and Type B)
3 years ago
Thanks for the explanation. I did try it out before posting the last reply and it does increase the capacity to 20, when we pass "abcd" to the constructor while creating an instance of StringBuilder. However, if I do an append, it does not increase the capacity unless and until it is required.
3 years ago
Sorry for the incorrect information in the post. As Zachary said, it happens when I create an instance of StringBuilder and pass a value in the constructor. That is when it prints the capacity as 20. It doesn't do the same when we do an append. As seen in the source code for StringBuilder it passes the string's length + 16 to the base, causing the capacity to be 20. I agree with Zachary, that we need not worry about the capacity at all in most of the scenarios. However, I was wondering is there any reason behind setting the capacity to size of string + 16, in the constructor of this class?
3 years ago
I was wondering, when we create an instance of StringBuilder, by default the capacity is taken as 16. However, after I execute sb.append("abcd"), the capacity value changes to 20? Why is that so? What is stored in the initially allocated memory space?
3 years ago
I was wondering, when we create an instance of StringBuilder, by default the capacity is taken as 16. However, after I sb.append("abcd"), when I check the capacity value again prints 20? Why is that so? What is stored in the initially allocated memory space?
3 years ago
I think I understand now. I went through various posts on stack overflow as well discussing the same thing and then tried with a sample code where the object of Chick class was created in some other class. So as long as the object uses the private member within the class, it works. If I create the Chick object in some other class, and try to access the private member of Chick, it shows me an error.
3 years ago

Why I am able to access a private member of a class using an instance of the same class? Doesn't that beat the purpose of data hiding?
I came across this example while reading through book "OCA Study Guide by Jeanne Boyarsky and Scott Selikoff". This example is given under Chapter 1 - Java Building Blocks, topic "Order of Initialization".
3 years ago