[Kde-java] java threads + events + segfaults
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Thu Apr 13 12:49:48 CEST 2006
Hi Benji
On Thursday 13 April 2006 10:48, Benji Weber wrote:
> Greetings,
>
> The below code produces segfaults such as
>
> #
> # An unexpected error has been detected by HotSpot Virtual Machine:
> #
> # SIGSEGV (0xb) at pc=0x00002aaaaaf88849, pid=1270, tid=1078753600
> #
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (1.5.0_06-b05 mixed mode)
> # Problematic frame:
> # C [libqtjava.so.1.0.0+0x261849]
> Java_org_kde_qt_QCustomEvent_finalize+0x49 #
> # An error report file with more information is saved as hs_err_pid1270.log
> #
> # If you would like to submit a bug report, please visit:
> # http://java.sun.com/webapps/bugreport/crash.jsp
> #
>
> After clicking the segfaults button, at some point after the message
> box has shown, moving/resizing the window tends to speed this up.
>
> If one stops the Event from being garbage collected as the "won't
> segfault" button does then there is no problem.
>
> Presumably this is an issue with qtjava?
>
> Benji
> ========================
>
> import org.kde.qt.*;
>
> public class ThreadTest extends QWidget
> {
> ThreadTest()
> {
> QVBoxLayout mainLayout = new QVBoxLayout(this,12,12,"MainLayout");
> mainLayout.setAutoAdd(true);
> QPushButton pushButton = new QPushButton("Segfaults",this,"Hello");
> //this will segfault at some point after message box shown - resizing
> or moving the window often triggers this
> QObject.connect( pushButton, SIGNAL( "clicked( )" ), this, SLOT(
> "onClick()" ) );
> QPushButton anotherPushButton = new QPushButton("won't
> segfault",this,"Hello2"); //this won't
> QObject.connect( anotherPushButton, SIGNAL( "clicked( )" ), this,
> SLOT( "onClick2()" ) );
> }
>
> private void onClick()
> {
> DoSomething doSomething = new DoSomething("test","test",this);
> doSomething.start();
> }
>
> private void onClick2()
> {
> DoSomethingElse doSomething = new DoSomethingElse("test","test",this);
> doSomething.start();
> }
>
>
> public static void main(String[] args)
> {
> QApplication myapp = new QApplication(args);
> ThreadTest mywidget = new ThreadTest();
> mywidget.setGeometry(50, 500, 400, 400);
>
> myapp.setMainWidget(mywidget);
> mywidget.show();
> myapp.exec();
> return;
> }
>
> public void customEvent(QCustomEvent evt)
> {
> System.out.println("got custom event");
> if (evt.type() == 65432)
> {
> MessageEvent event = (MessageEvent) evt;
> System.out.println(event.getTitle());
> QMessageBox.critical(this,event.getTitle(), event.getText());
> }
> }
>
> static {
> qtjava.initialize();
> }
> }
>
> class DoSomething extends Thread
> {
> private String text;
> private String title;
> private QWidget caller;
>
> public DoSomething(String title, String text,QWidget caller)
> {
> this.caller = caller;
> this.text = text;
> this.title = title;
> }
> public void run()
> {
> System.out.println("Thread running");
> MessageEvent event = new MessageEvent(title,text);
> QApplication.postEvent(caller,event);
> System.out.println("Thread finishing");
> }
> }
>
> class DoSomethingElse extends Thread
> {
> private String text;
> private String title;
> private QWidget caller;
>
> public DoSomethingElse(String title, String text,QWidget caller)
> {
> this.caller = caller;
> this.text = text;
> this.title = title;
> }
> public void run()
> {
> System.out.println("Thread running");
> MessageEvent event = new MessageEvent(title,text);
> QApplication.postEvent(caller,event);
> dont.gc(event);
> System.out.println("Thread finishing");
> }
> }
>
> class dont //xxx
> {
> private static java.util.ArrayList dump = new java.util.ArrayList();
> static void gc(java.lang.Object o)
> {
> dump.add(o);
> }
> }
>
> class MessageEvent extends QCustomEvent
> {
> private String title;
> private String text;
> public MessageEvent(String title, String text)
> {
> super(65432);
> this.title = title;
> this.text = text;
> }
>
> public String getTitle(){return title;}
> public String getText(){return text;}
> }
I think you'd be better off using the pretty much undocumented QtUtils class
for this. Have a look at the code in QtUtils.cpp and QtUtils.java, and see if
it seems to be what you want. I'm afraid I didn't write it and don't know
much about it, but I think it does work and allows you to coordinate Java
threads with a Qt one.
Regards
-- Richard
More information about the Kde-java
mailing list