Computer
Microsoft is Bringing Video Wallpapers To Windows 11
Read more of this story at Slashdot.
Nvidia To Invest $100 Billion in OpenAI
Read more of this story at Slashdot.
China Road Trip Exposes List of Uninvestable Assets in the West
Read more of this story at Slashdot.
Is Amazon Prime Too Hard To Cancel? A Jury Will Decide.
Read more of this story at Slashdot.
The Rush To Return to the Office Is Stalling
Read more of this story at Slashdot.
JPMorgan Says $100K 'Prices Out H-1B' as Indian IT Giants May Accelerate Offshoring With Remote Delivery Already Proven at Scale
Read more of this story at Slashdot.
Is There a Market for Meta's Ray-Ban Display Smart Glasses? (How About the Blind?)
Read more of this story at Slashdot.
Reddit Wants 'Deeper Integration' with Google in Exchange for Licensed AI Training Data
Read more of this story at Slashdot.
CodeSOD: Identify a Nap
Guy picked up a bug ticket. There was a Hiesenbug; sometimes, saving a new entry in the application resulted in a duplicate primary key error, which should never happen.
The error was in the message-bus implementation someone else at the company had inner-platformed together, and it didn't take long to understand why it failed.
/** * This generator is used to generate message ids. * This implementation merely returns the current timestamp as long. * * We are, thus, limited to insert 1000 new messages per second. * That throughput seems reasonable in regard with the overall * processing of a ticket. * * Might have to re-consider that if needed. * */ public class IdGenerator implements IdentifierGenerator { long previousId; @Override public synchronized Long generate (SessionImplementor session, Object parent) throws HibernateException { long newId = new Date().getTime(); if (newId == previousId) { try { Thread.sleep(1); } catch (InterruptedException ignore) {} newId = new Date().getTime(); } return newId; } }This generates IDs based off of the current timestamp. If too many requests come in and we start seeing repeating IDs, we sleep for a second and then try again.
This… this is just an autoincrementing counter with extra steps. Which most, but I suppose not all databases supply natively. It does save you the trouble of storing the current counter value outside of a running program, I guess, but at the cost of having your application take a break when it's under heavier than average load.
One thing you might note is absent here: generate doesn't update previousId. Which does, at least, mean we won't ever sleep for a second. But it also means we're not doing anything to avoid collisions here. But that, as it turns out, isn't really that much of a problem. Why?
Because this application doesn't just run on a single server. It's distributed across a handful of nodes, both for load balancing and resiliency. Which means even if the code properly updated previousId, this still wouldn't prevent collisions across multiple nodes, unless they suddenly start syncing previousId amongst each other.
I guess the fix might be to combine a timestamp with something unique to each machine, like… I don't know… hmmm… maybe the MAC address on one of their network interfaces? Oh! Or maybe you could use a sufficiently large random number, like really large. 128-bits or something. Or, if you're getting really fancy, combine the timestamp with some randomness. I dunno, something like that really sounds like it could get you to some kind of universally unique value.
Then again, since the throughput is well under 1,000 messages per second, you could probably also just let your database handle it, and maybe not generate the IDs in code.
[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.Could Wildfire Smoke Become America's Leading Climate Health Threat By 2050?
Read more of this story at Slashdot.
Apple Watch's New High Blood Pressure Notifications Developed With AI
Read more of this story at Slashdot.
Astronomers Discover Previously Unknown Quasi-Moon Near Earth
Read more of this story at Slashdot.
Why One Computer Science Professor is 'Feeling Cranky About AI' in Education
Read more of this story at Slashdot.
AI Tools Give Dangerous Powers to Cyberattackers, Security Researchers Warn
Read more of this story at Slashdot.
More Durable UV Coating For Solar Panels Made From Red Onion Skins
Read more of this story at Slashdot.
Meta's UK Arbitration 'Threatens to Bankrupt' Facebook Whistleblower, Says Her Lawyer
Read more of this story at Slashdot.
America's Space Force is Preparing for a New Kind of War
Read more of this story at Slashdot.
Hundreds of Google AI Workers Were Fired Amid Fight Over Working Conditions
Read more of this story at Slashdot.
Secure Software Supply Chains, Urges Former Go Lead Russ Cox
Read more of this story at Slashdot.
Tech Boomtown Seattle Grapples with Fewer Tech Jobs
Read more of this story at Slashdot.
