How to make a stack universal for working not only with Integer but also with String and custom objects?
Java
What should be considered when creating an index on a large table in production?
Write your own class that implements a stack with methods push, pop, and peekMax, which returns the max element in the stack in O(1).
Why is SELECT FOR UPDATE needed instead of synchronized? And why pessimistic locking instead of optimistic?
Why will a StackOverflowError occur if there are no local variables? What will the memory fill with?
Why can't we just use a single max variable instead of a second stack?
What to do if processFile cannot be executed after a transaction commit?
There is a system that allows users to work with files in the browser. The stack is standard: Java, Spring, React, Postgres. Files are stored in the file system on the backend, file metadata in the database. The team implemented a feature: @Transactional public void process(String oldName, String newName) { Long id = exec("select id from file where name='" + oldName + "'"); // executing a database query processFile(oldName, newName); // renaming the file on disk exec("update file set name='" + newName + "' where id = " + id); // executing a database query }
Is it possible to optimize the stack for memory so that there is no x2 consumption?
There is a backend, there is a UI. The stack is standard: Java, Spring, React, Postgres. Task: Design a REST endpoint that takes data from 3 sources and returns it to the UI, while ensuring maximum throughput and minimal response time (max/min criteria based on our specific conditions, since there is no silver bullet and we need to find a compromise). It is known that the expected peak RPS for this REST endpoint will be 200. Details about sources: 1st source - our database, query takes about 15 seconds. 2nd source - a related REST service, degrades to 2 minutes at 100 RPS, normally responds in 5 seconds. We cannot change this source's behavior. 3rd source - another related REST service, randomly (no pattern found) returns 503, normally responds in 10 seconds. We cannot change this source's behavior.
What type of index should be used for searching in the middle or end of a string (LIKE '%text%')?
Write the simplest method that would throw a StackOverflowError during execution.