string search using OQL
Asked Answered
V

4

21

I am using VisualVM to analyze a core dump. I suspect some XML objects to be causing the leak but there are way too many String objects to go through one by one.

Can I use OQL to search String that begin with 'GH' ?

thanks for any help.

Valenzuela answered 17/7, 2012 at 17:15 Comment(0)
D
24

Try this: select {instance: s, content: s.toString()} from java.lang.String s where s.count>2 && s.toString().substring(0,2)=="GH"

Donaghue answered 18/7, 2012 at 13:53 Comment(0)
Q
32

under JDK 1.8.20 a more simple variant works:

select s from java.lang.String s where s.toString().startsWith("GH")
Qp answered 8/10, 2014 at 14:12 Comment(2)
Thank you for this. Where do you find documentation for all the supported methods? Googling only leads to random blogs that don't workDulles
just looked at the answer below and guessed that startsWith could work. also as I heard it's possible to use sql with a heap dumpQp
D
24

Try this: select {instance: s, content: s.toString()} from java.lang.String s where s.count>2 && s.toString().substring(0,2)=="GH"

Donaghue answered 18/7, 2012 at 13:53 Comment(0)
R
6
heap.objects('java.lang.String', false, "it.toString().startsWith('GH')")
Reld answered 22/12, 2016 at 14:44 Comment(1)
A short ummary would help reviewers (like me) to judge the validity of your answer; interested users wouldn't have to dive into the code to understand your appoach. Just a sentence or two would be fine and not too much work.Giffard
L
-1

select c.attr_name.toString() from a.b.c.MyClass c where c.attr_name.toString().startsWith("GH")

Lynnet answered 26/12, 2019 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.