Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS266 Practical Class 4— Introducing
JCSP
Learning Outcome: You will understand how to put processes in
parallel using a specialised Java library which supports concur-
rency.
Getting Started - JCSP
• You will need to log into one of the departmental servers, exactly as
you did for the other pieces of software used on the course. See the
Lab Instructions.
• Once you have opened up a unix shell type:
source /opt/bin/cs266setup
You will need to run this cs266setup script in all the unix
windows you want to use to compile your code.
This will add the JCSP libraries to your CLASSPATH so that it can
pick up the relevant JCSP classes when you compile your code. If you
do
echo $CLASSPATH
on the command line you will see two references to .jar
1 Try out some code which do not communicate
between each other
This is the code from lecture 8.
• Download the three files ProcessOne.java, ProcessTwo.java, and
RunMe.java from the website.
1
• Compile all the programs on the command line:
javac ProcessOne.java
javac ProcessTwo.java
javac RunMe.java
2 Try out some sample code which communicates
between objects
Lecture 9 covered communication between objects.
• Download the three files P.java, Q.java, and Lab4Example1.java
from the website.
• Compile all the programs on the command line:
javac P.java
javac Q.java
javac Lab4Example1.java
• Run the example program by typing java Lab4Example1. Does the
program terminate? No, because both the run methods of the P and
Q objects are running forever. Press CTRL-C to quit the program.
• Open up a web browser and go to http://www.cs.kent/projects/ofa/jcsp.
Find the Browse the documentation online. Find the jcsp.lang
package, then look under the class summary for details of the class
One2OneChannelInt. This is the communication channel used in
our first example. Familiarise yourself with the method summary so
that you can see that the read and write methods are those that P
and Q use in their respective definitions.
3 Try changing some sample code
• Download two files Filter.java and Lab4Example2.java.
• Fill in the body of the Filter.java so that it does what the comment
says. Then compile and run the program.
2
• Notice that this time we make use of another built in class NumbersInt.
This is an integer generator. It produces integers on its output channel.
You will find it in the org.jcsp.plugNplay.ints. Familiarise yourself
with the documentation of this class.
3