tag:blogger.com,1999:blog-694855878384792308.post3289343846503596864..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to do Inter process communication in Java? MemoryMapped File Example Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-694855878384792308.post-4483273576457148712022-01-11T15:14:42.110-08:002022-01-11T15:14:42.110-08:00Thanks. Can you please explain what could happen w...Thanks. Can you please explain what could happen without the "Thread.sleep(1);"?<br />Can we use "mem.put" to write the whole buffer and only then sleep?<br />1ms is enough because we just need to make sure there's a context switch?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-60797573838670021842021-10-18T21:38:13.842-07:002021-10-18T21:38:13.842-07:00Hello Shiv, just make the method synchronized, thi...Hello Shiv, just make the method synchronized, this will ensure that only one thread can go inside the method at anytime, you can also put<br /><br />System.out.println("Going in" + Thread.getCurrentThread().getName()) and similar text at the end of method to confirm this behavior. <br /><br />All the best, if you face any issue, please chat the error here. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-35265998719689910202021-10-18T21:36:07.843-07:002021-10-18T21:36:07.843-07:00Just call the notifyAll() or notify() method, the ...Just call the notifyAll() or notify() method, the 10000 ms wait here is for demonstration purpose. its not required in real world projects. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-5833781225146489192021-09-23T03:09:54.596-07:002021-09-23T03:09:54.596-07:00Hi Javin,
I have doubt related to synchronization ...Hi Javin,<br />I have doubt related to synchronization between 2 or more process.<br />Here, 2 more process are trying to access the same java function which is trying to update the value in text file. How can i create lock for that function, such that at 1 time only process can access the function. <br />Thank youShivhttps://www.blogger.com/profile/15096263833668912892noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-78407073506042078162021-04-25T23:49:25.242-07:002021-04-25T23:49:25.242-07:00Hey Anonymous, thx for comment, what was the error...Hey Anonymous, thx for comment, what was the error you are talking about? can you please explain bit more for readers?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-67984157720879254962021-04-11T01:08:51.861-07:002021-04-11T01:08:51.861-07:00Error in above code
Working code is below
import...Error in above code <br />Working code is below<br /><br />import java.io.IOException;<br />import java.io.RandomAccessFile;<br />import java.nio.MappedByteBuffer;<br />import java.nio.channels.FileChannel;<br /><br />public class Exp_3_Producer <br />{<br /> public static void main(String args[]) throws IOException, InterruptedException <br /> {<br /> RandomAccessFile rd = new RandomAccessFile("C:/Data/TCET/Sem 8/DC/mapped.txt", "rw");<br /> FileChannel fc = rd.getChannel();<br /> MappedByteBuffer mem = fc.map(FileChannel.MapMode.READ_WRITE, 0, 1000);<br /> try <br /> {<br /> Thread.sleep(10000);<br /> } <br /> catch (InterruptedException e) <br /> {<br /> e.printStackTrace();<br /> }<br /> <br /> for(int i=1; i < 10; i++) <br /> { <br /> mem.put( (byte) i);<br /> System.out.println("Process 1 : " + (byte)i );<br /> Thread.sleep(1); // time to allow CPU cache refreshed<br /> }<br /> }<br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-3833401274783279432020-11-13T05:36:22.079-08:002020-11-13T05:36:22.079-08:00Hello Vladimir, looks like some formatting issue, ...Hello Vladimir, looks like some formatting issue, did you try running the programmer, it should be something like i=1; i< mem.put((byte) i); i++)javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-26489438115739616142020-11-08T12:17:54.143-08:002020-11-08T12:17:54.143-08:00Hi, how to understand to this row: for(int i=1; i...Hi, how to understand to this row: for(int i=1; i mem.put( (byte) i);<br /><br />Thank you, vladimirAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-61189982130181252942020-08-26T22:08:42.002-07:002020-08-26T22:08:42.002-07:00waiting for 10000 ms is a long time. how can a pro...waiting for 10000 ms is a long time. how can a process notify the other as soon as it finishes?Anonymoushttps://www.blogger.com/profile/18174456918194795659noreply@blogger.com