Page 1 of 1

PHP5 and Java Integration Using PHP-Java bridge.

Posted: Tue Aug 01, 2006 8:28 am
by ptobra
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have successfully integrated PHP5 and Java using PHP-Java bridge. 
Can any one help how we can run a simple Thread application by importing java.lang.Thread or implementing Runnable interface in PHP. This thing has to be run on terminal and not on webserver.

A simple Thread program which i run is :

Code: Select all

<?
$thread=new Java('java.lang.Thread');
for($i=0;$i<10;$i++){
        echo " \n ". $i . " hello ";
$thread->sleep(1000);
}
?>
OUtput:

Code: Select all

C:\test\javatest>php test4.php

 0 hello
 1 hello
 2 hello
 3 hello
 4 hello
 5 hello
 6 hello
 7 hello
 8 hello
 9 hello
Another small program

Code: Select all

<?
class MyThread{
        function __construct($msg){

        $obj=new JavaClass("java.lang.Thread");
        $thread=$obj->newInstance();
        $thread->setName($msg);
                echo " \nThread " . $thread->getName() . "  Running ";
        $thread->sleep(3000);
        }
}
$a= new MyThread("hello world");
$b= new MyThread("there is me");
?>
Output:

Code: Select all

C:\test\javatest>php test6.php

Thread hello world  Running
Thread there is me  Running
Can any one help me how we can implement interfaces of java in php or how we can use synchronization ( we can or we cannot??? ) keyword for synchronization .????


8O 8O 8O Thanks in advance.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]