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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • The Production-Ready Kubernetes Service Checklist

Trending

  • From Monolith to Containers: Real-World Migration Blueprint
  • Enterprise-Grade Distributed JMeter Load Testing on Kubernetes: A Scalable, CI/CD-Driven DevOps Approach
  • How You Can Use Few-Shot Learning In LLM Prompting To Improve Its Performance
  • When Caching Goes Wrong: How One Misconfigured Cache Took Down an Entire System
  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
9.5K 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

  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • The Production-Ready Kubernetes Service Checklist

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: