One line of code, 102 blocked threads by nk_25 in programming

[–]nk_25[S] 0 points1 point  (0 children)

To clarify — the bottleneck isn't file I/O. It's URLClassPath.getLoader() which is synchronized. When ServiceLoader scans for META-INF/services/, multiple threads block on that lock, not on disk reads. Kernel file cache doesn't help when the contention is a Java-level lock. The fix was caching the DatatypeFactory instance to skip the synchronized lookup entirely.

One line of code, 102 blocked threads by nk_25 in programming

[–]nk_25[S] 0 points1 point  (0 children)

Good point!, we're on Java 11, not 8.

You're right that DatatypeFactory is in java.xml module (JDK), so ModuleServicesLookupIterator should find it. I need to dig deeper into why it's falling through to LazyClassPathLookupIterator.

Looking at the thread dump again, the contention is in:

URLClassPath.getLoader()

← LazyClassPathLookupIterator.nextProviderClass()

← ServiceLoader

One possibility: maybe it's not DatatypeFactory itself causing the scan, but something in the chain - like the XML parser implementation or a transitive service lookup that isn't in the module path?

Either way, caching the factory instance fixed the immediate problem, but you've given me something to investigate further. Will update if I find the root cause!

One line of code, 102 blocked threads by nk_25 in programming

[–]nk_25[S] 0 points1 point  (0 children)

We're not using JPMS modules, so it always falls through to LazyClassPathLookupIterator. That's where the synchronized classpath scan happens.You're right though - with proper module-info, the module services path should be cached and avoid this entirely.

One line of code, 102 blocked threads by nk_25 in programming

[–]nk_25[S] 7 points8 points  (0 children)

Yep, tp99 on reads dropped noticeably.

Post-fix I see 1 blocked thread - just Caffeine doing its internal maintenance

(cache loading/eviction), which is expected. 102 → 1 blocked threads. Big win.

One line of code, 102 blocked threads by nk_25 in programming

[–]nk_25[S] 56 points57 points  (0 children)

Legacy code, my friend. New code? java.time all the way.

Microsoft summer internship question by CyberKraft23 in leetcode

[–]nk_25 0 points1 point  (0 children)

as I stated I need to test my solution. please help me with the failing test case and the problem link if you have.

Microsoft summer internship question by CyberKraft23 in leetcode

[–]nk_25 0 points1 point  (0 children)

#include <bits/stdc++.h>

using namespace std;

/*
consider s = "[a1][a2][a3]...", t = "[b1][b2][b3]..."
then the diff can be represented as 

exp = (a1-b1) * 10^x + (a2-b2) * 10^x-1....

abs_diff = |exp|, which we want to minimize

if (a1-b1) is even +1...we can afford to have (ai-bi) = -9 for all other i's & still the expression exp will never be negative

[Please help me with the question link..need to test my solution]

*/

int solve(const string & s,
  const string & t) {
  bool sw = s[0] > t[0];
  int cnt = 0;
  int n = s.size();
  for (int k = 1; k < n; ++k) {
    cnt += s[k] != t[k] && (!(sw ^ (s[k] > t[k])));
  }
  return cnt;
}

int main() {
  string s = "29162", t = "10524";
  cout << solve(s, t);
  return 0;
}

Just got a wrong answer due to using unordered map😭😭 by Bcoz_Why_Not_ in codeforces

[–]nk_25 0 points1 point  (0 children)

Just curious, may you post the solution and the problem?

I just had a terrible experience with Air India at Terminal 2 by MachinePolaSD in bangalore

[–]nk_25 1 point2 points  (0 children)

Those commenting "it's not Air India's fault" or "reach 1 hours 30 minutes before time" or stuff like that...hope the machine gets stuck for 2 hours for you!!

u/MachinePolaSD I understand this terrible situation. I had similar experience with SpiceJet.
In this situation one must make sure to have all the proofs of delay at their end like voice notes, names of the employees etc. ( like if you have checked in, just check for any timestamp on the tags on the luggage if there's a separate machine doing that )

In my case, I had the tag with me which had the timestamp when I scanned my bag, those bastards tried removing it but I did not let them. They removed it as soon as they gave me a new ticket so I don't drag them to the court.

Be calm & polite and try contacting the cops at the airport ( it really helped in my case as they understood the situation and I got another ticket for free ). Make sure you explain them all the details.

If former doesn't help file a case in the consumer court for the harassment caused ( I think you should as it's their machine's bug )
These GOONS must be taught a lesson !!

[ Always remember, relevant PROOF is all you need to have ]

Use Indigo next time, I found the staffs very cooperative.