DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • One Query, Four GPUs: Tracing a Distributed Training Stall Across Nodes
  • Pragmatic Paths to On-Device AI on Android with ML Kit
  • Deep Linking in Enterprise Android Apps: A Real-World, Scalable Approach
  • Diving into JNI: My Messy Adventures With C++ in Android

Trending

  • Zero-Downtime Deployments for Java Apps on Kubernetes
  • Beyond Manual Annotation: Engineering Self-Correcting Pseudo-Labeling Pipelines
  • Using LLMs to Automate Data Cleaning and Transformation Pipelines
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Cluster an Android Phone and a PC Using JavaX

How to Cluster an Android Phone and a PC Using JavaX

Yes, you can cluster an Android phone and a PC using JavaX! Stefan Reich shows us this quick tutorial on how to do so. It's easier than you think.

By 
Stefan Reich user avatar
Stefan Reich
·
Aug. 25, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
10.0K Views

Join the DZone community and get the full member experience.

Join For Free

Remember the old days of the Commodore 64? It had a 1 MHz CPU which could run up to half an instruction per clock. It also had a disk drive which contained the exact same CPU.

Usually, the drive's processor didn't do much except when loading and saving. But some smart people actually turned the computer + drive combo into a sort of cluster, calculating Mandelbrot sets on both machines in parallel.

Today, you can do a similar thing with your PC and your smartphone — it’s got a processor too. Typically, today, even a multi-core.

But normally you can’t access the phone’s processor directly. It will only run its predefined apps.

Don’t worry: Once again the miracle language will help— JavaX will make your PC and your phone act as a cluster.

Let’s check it out. All you need is the app on the phone and this program on the PC.

Connect the phone to the PC with a USB cable. Start the app on the phone and hit the “Start Awareness” button. It will make the phone “aware”, i.e. able to receive commands.

Also, sadly, because Android is a very limited platform, you need to convince it to even allow communication between the devices. You do this by either turning on “USB tethering” on the phone,or by installing “adb” on the PC (the Android debugger). Either way should be okay, JavaX will try to make it work.

Now we’re good to go. Start the PC program and you’ll have our fancy Java interpreter prompt ready for you. You can now, with one function call (“quickPhoneEval”), run JavaX code on the phone! This is what the program looks like:

It can run Java code on the fly with the "!j" command. So a simple test line for our purposes would be:

!j quickPhoneEval("1+2")

…which will indeed return 3 as expected. We can verify that this actually ran on the phone like so:

!j quickPhoneEval([[System.getProperty("java.vendor")]])

…which, on my device, says “The Android Project”.

This is the more complicated command from the screenshot:

!j quickPhoneEval([[l(listFiles(new File(androidHome(), ".javax")))]])

This will show how many temp directories JavaX has created on the Android phone.

(The [[ ]] brackets are multi-line string literals in JavaX. I borrowed this syntax from Lua.)

This looks simple, right? And it is. Notice also how we can use any JavaX standard function just by calling its name.

What goes on behind the scene is not quite so simple. Java code is made, compiled (to .class/.dex) and run, both on the PC and on the phone, and objects are wrapped and unwrapped automatically when transferring them between the devices. When all is done, the phone cleans up all the temporary classes it made.

You can even make a List or a Map on the phone and further process it on the PC.

For another example, check out this program which makes the PC and the phone speak at the same time (with different voices).

You know what? We should start calculation competitions. My phone has got a quad-core processor, but I am doubtful it will beat the PC’s single core CPU, even with parallelization. But do I know for sure? No, I didn’t run any numbers yet. Let’s make a benchmark and see how they stack up! It’s all a one-liner in JavaX…

Android (robot) cluster

Opinions expressed by DZone contributors are their own.

Related

  • One Query, Four GPUs: Tracing a Distributed Training Stall Across Nodes
  • Pragmatic Paths to On-Device AI on Android with ML Kit
  • Deep Linking in Enterprise Android Apps: A Real-World, Scalable Approach
  • Diving into JNI: My Messy Adventures With C++ in Android

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook