It seems that jdb cannot accept commands from command line, so we must use expect.
I created the following expect script dumpthreads
You can use it like:
dumpthreads java_process_pid

#!/usr/bin/expect
set pid [lindex $argv 0];
spawn jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=$pid;
expect ">";
send "threads\n";
expect ">";
send "quit\n";