Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Nicholas Barbosa

Ranch Hand
+ Follow
since Jun 04, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
1
Total given
13
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nicholas Barbosa

Campbell Ritchie wrote:Please don't quote the whole of the preceding post. Please tell us what the solution was.


Suppose thread1 acquire lock for alphonse and thread2 acquire lock for gaston. Thread1 and Thread2 execute line 30, on line 38 in bowBack() there is another lock so thread1 try to acquire this lock for gaston however gaston object is  already in a lock trying to acquire a lock for alphons object which is also already in a lock. So both are blocked forever one waiting for the other.

The second examples does not make sense, cause the lock will be granted to the object of the bow() argument and not the object which is calling the bow () method.
Hi,

I took an deadlock code example from Oracle docs. Follow

Now, follow the second example with the same part of the code but with some modifications

Why the second example not occurs a deadlock?

Paul Clapham wrote:Are you simply asserting that an exception will be thrown, or do you have some evidence for that statement?

(By the way: when you make a post, isn't there an "Attachments" tab at the bottom of the box where you type your post? Using that would be much preferred compared to making readers go to some other site.)



Yes!



If "target" not exists, an exception will be thrown. In case you haven't tested the photo code, here is a problem related to APPEND enum value in the stackoverflow.

Stackoverflow->https://stackoverflow.com/questions/30908816/java-nio-file-nosuchfileexception-why-nio-not-creating-file

Excerpt from the stackoverflow response that proves that the letter C is correct and not B, "You're using StandardOpenOption.APPEND, but that won't create a file; it will append to an existing file."
Hi,

Using APPEND, if the target file already exists, the contents of source file will be append to the end of target file and if the target not exists will be thrown an exception.

Making letter C and E correct.

Img -> https://ibb.co/N7T7Y04
Hi,

Using APPEND, if the target file already exists, the contents of source file will be append to the end of target file and if the target not exists will be thrown an exception.

Making letter C and E correct.

Img -> https://ibb.co/N7T7Y04
Hi,

Im studying for 1Z0-819 certificate and I saw that you must movel all projects from classpath to module path at once, please tell me if i got it right why.

The reason is, named modules cannot access unnamed modules.Using top down strategy, all projects that are not named modules(high-level) are automatic modules(low-level), cause named can access automatic modules. In this scenario, if the automatic modules(low-level) were unnamed, high-level modules that reference this low-level module, would have problems since the named module cannot access unnamed.

Working with bottom up, you dont need move everything at once, cause the projects that have been migrated are named modules(low-level) and the projects that have not been migrated are unnamed modules(high-level).In this scenario, high-level projects are unnamed modules and they can access your dependencies that are named modules already migrated.

Right?
3 weeks ago

Early Charlemagne wrote:Hi,

I have a query about Automatic modules.
On Chapter 6 in the Java OCP 11 Programmer II Study Guide by Scott Selikoff and Jeanne Boyarsky it's written "A key point to remember is that code on the classpath can access the module path. By contrast, code on the module path is unable to read from the classpath."
Also, looking at Table 6.3 (see attachment) I understand that Automatic modules cannot access unnamed modules on the classpath.

However, I read elsewhere the following:
Remember that modular code cannot access code present on the -classpath but "automatic modules" are an exception to this rule. When a non-modular jar is put on --module-path, it becomes an "automatic module" but it can still access all the modular as well as non-modular code. In other words, a class from an automatic module can access classes present on --module-path as well as on -classpath without having any "requires" clause

Did I misunderstand the information in Java OCP 11 Programmer II Study Guide?




Hi,

Unnamed modules are on the classpath. They can access JAR files on both the classpath and the module path.

Named modules are on the module path, they cant access any unnamed module.

Automatic module are on the module path, they can access all the modular as well as non-modular code.

For example, using Bottom-Up migration strategy, you have a mix of named and unnamed modules.The named modules are the low-level that have been migrated. They are on the module path and not allowed to access any unnamed modules, but the high-level that have not been migrated are unnamed and they access the low-level(named).

Another example, top-down migration, you move all projects to module path(now they are automatic modules), then you choose the first module that has more dependencies to add the module-info to convert the automatic module into a named module. If the modules that are low-level(have less dependence) were unnamed (that is, they were in the classpath) this strategy would not work, since named modules cannot access unnamed modules.Thats why you must move all projects to module path, using this strategy.
Hi Mihail,iWhen I did question 15, I thought it was an INOUT so the letter C was true for me.

Since the same param refers ta IN and OUT param,should be cs.setInt (1, 8);
double_number is an INOUT.



Should be since ?= is optional?

Im studying for the 1Z0-819 exam.

I know about wrapping process, high level stream take a low level instance in your constructor. I want to know if read(byte b), read(byte[]b) and read(byte[]b,int off,int len) have the same performance with buffered classes. Cause both read(byte[]b) and read(byte[]b,int off,int len) call repeatedly rea(byte b).

1 month ago
I have a doubt between BufferedInputStream(high level) and FileInputStream(low-level). I know Buffered is better than FileInputStream cause Buffered write/read datas in group of bytes or characters.

My doubt: With BufferedInputStream, read(byte b), read(byte[]b), read(byte[] b,int offset,int len) are equal in relation to performance? Because read(byte[] b,int offset,int len) and read(byte[]b) call read() repeatedly, however the bytes are stored into a array using read(byte[]b) and  read(byte[]b,int off,int len), while read() returns a single byte.
1 month ago
Hi guys,now I understood my doubts.Briefly, Threads in AtomicClasses like in monitor/lock(synchronized), of course with some differences ,waits the previous thread to execute your own task(increment and report).

Thank you all!

Paul,single unit of execution is an analogy of next thread wait the previous thread execute the task without any interference by another thread.

Paul Clapham wrote:I'm sorry, I still don't understand what it means to "retake looping".

Instead let me try again with an explanation of what happens. The ExecutorService is given 10 Runnable objects to execute. This happens almost immediately as there's a loop which gives the objects to the ExecutorService. In case it isn't clear, the loop doesn't execute the Runnable objects in any way.

When the ExecutorService executes one of those objects, the object sleeps for a while and then increments/prints the value of the AtomicInteger.



There is one exectuorService which has 10 tasks to perform, creating 10 threads for each task. How you can see, I created a pool of threads using newCachedThreadPool() from Executors factory class.I'm ordering the thread that will execute the next runnable task, slleep for a specified number of times, if I compile and run that code without atomic property, we would have many threads overwriting the result of another thread. By the way I used the AtomicInteger class to make this operation thread-safe. Any thread trying to access the count variable while an atomic operation is in process will have to wait until the atomic operation is complete.So, our operation is running in a single unit of execution.

However we have a delay(Thread.sleep) to submit another task to the single unit of execution and the for ends first than our executorService complete all tasks.
Ok, the thread executor retakes the looping?Because I call Thread.sleep() and the loop terminates first than executor.