Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
0a400444
Commit
0a400444
authored
Sep 15, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
synchronized
parent
42e2ce95
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
Konto.java
...ansowaneElementyJavy/src/main/java/watki/konto/Konto.java
+7
-3
No files found.
PC22-ZaawansowaneElementyJavy/src/main/java/watki/konto/Konto.java
View file @
0a400444
...
@@ -23,7 +23,7 @@ public class Konto {
...
@@ -23,7 +23,7 @@ public class Konto {
return
numer
;
return
numer
;
}
}
public
int
getSaldo
()
{
public
synchronized
int
getSaldo
()
{
return
saldo
;
return
saldo
;
}
}
...
@@ -32,7 +32,11 @@ public class Konto {
...
@@ -32,7 +32,11 @@ public class Konto {
return
"Konto nr "
+
numer
+
", wł. "
+
wlasciciel
+
", saldo: "
+
saldo
;
return
"Konto nr "
+
numer
+
", wł. "
+
wlasciciel
+
", saldo: "
+
saldo
;
}
}
public
void
wplata
(
int
kwota
)
{
// Gdy metoda jest synchronizowana, to zapobiega jednoczesnemu wykonywaniu jej treści przez równe wątki.
// Dokładnie: Gdy jeden wątek wykonuje JAKĄKOLWIEK metodę synchronizowaną na danym obiekcie,
// to żaden INNY wątek nie może rozpocząć wykonywania JAKIEJKOLWIEK metody synchronizowanej NA TYM SAMYM OBIEKCIE.
// Wątek, który próbuje wejść do takiej metody, zostanie wstrzymany i wpuszczony dopiero, gdy obiekt będzie wolny.
public
synchronized
void
wplata
(
int
kwota
)
{
if
(
kwota
<=
0
)
{
if
(
kwota
<=
0
)
{
throw
new
IllegalArgumentException
(
"Ujemna kwota w wplata"
);
throw
new
IllegalArgumentException
(
"Ujemna kwota w wplata"
);
}
}
...
@@ -40,7 +44,7 @@ public class Konto {
...
@@ -40,7 +44,7 @@ public class Konto {
notify
();
notify
();
}
}
public
void
wyplata
(
int
kwota
)
throws
BrakSrodkow
{
public
synchronized
void
wyplata
(
int
kwota
)
throws
BrakSrodkow
{
if
(
kwota
<=
0
)
{
if
(
kwota
<=
0
)
{
throw
new
IllegalArgumentException
(
"Ujemna kwota w wyplata"
);
throw
new
IllegalArgumentException
(
"Ujemna kwota w wyplata"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment