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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • 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

Trending

  • You Don't Have to Pick One: A Hybrid Approach to Enterprise Data Refresh
  • Your Agents Think Data Federation Means One Truth. It Means a Collage.
  • PWA on iOS, Part 1: PWAs on the iPhone Are Older Than They Look
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Aug. 25, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
10.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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